K
Khonsort
Hello,
I've spent the last 2 days to try to run a simple c# program which just open
an Excel 2003 Workbook and try to copy one of his Worksheet at the end of is
Sheets collection. That don't work ! I just get the error message :
Code SnippetLe serveur a généré une exception. (Exception de HRESULT :
0x80010105 (RPC_E_SERVERFAULT))
à Microsoft.Office.Interop.Excel._Worksheet.Copy(Object Before, Object
After)
à ConsoleApplicationExcelAutomation.Program.Main(String[] args) dans
C:\Developpements\VS2005\Tests\ConsoleApplicationExcelAutomation\Program.cs:ligne 27
Environment configuration
Windows XP SP2 French
Excel 2003 SP3 (11.8169.8172) French
Here is the complete source code :
=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-==-=-=-=-
using System.Collections.Generic;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace ConsoleApplicationExcelAutomation {
class Program {
static void Main( string[] args ) {
Excel._Application xlApp = null;
try {
xlApp = new Excel.Application();
xlApp.Visible = true;
Excel._Workbook xlBook = null;
try {
xlBook = xlApp.Workbooks.Open( @"C:\Documents and
Settings\fprevost\Mes documents\Classeur_test_PA2003.xls",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value );
try {
( (Excel._Worksheet) xlBook.Sheets[1] ).Copy( Missing.Value,
xlBook.Sheets[2] );
}
catch ( Exception ex ) {
System.Console.Out.WriteLine( ex.Message );
System.Console.Out.WriteLine( ex.StackTrace );
}
System.Console.In.ReadLine();
}
finally {
if ( xlBook != null ) {
xlBook.Close( false, Missing.Value, Missing.Value );
xlBook = null;
}
}
}
catch ( Exception ex ) {
System.Console.Out.WriteLine( ex.Message );
System.Console.Out.WriteLine( ex.StackTrace );
System.Console.In.ReadLine();
}
finally {
if ( xlApp != null ) {
xlApp.Quit();
xlApp = null;
GC.Collect();
}
}
}
}
}
=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-==-=-=-=-
Can anybody try to complie and run successfully this code ? or explain me
why that goes wrong ?
Thanks in advance for any help.
I've spent the last 2 days to try to run a simple c# program which just open
an Excel 2003 Workbook and try to copy one of his Worksheet at the end of is
Sheets collection. That don't work ! I just get the error message :
Code SnippetLe serveur a généré une exception. (Exception de HRESULT :
0x80010105 (RPC_E_SERVERFAULT))
à Microsoft.Office.Interop.Excel._Worksheet.Copy(Object Before, Object
After)
à ConsoleApplicationExcelAutomation.Program.Main(String[] args) dans
C:\Developpements\VS2005\Tests\ConsoleApplicationExcelAutomation\Program.cs:ligne 27
Environment configuration
Windows XP SP2 French
Excel 2003 SP3 (11.8169.8172) French
Here is the complete source code :
=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-==-=-=-=-
using System.Collections.Generic;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace ConsoleApplicationExcelAutomation {
class Program {
static void Main( string[] args ) {
Excel._Application xlApp = null;
try {
xlApp = new Excel.Application();
xlApp.Visible = true;
Excel._Workbook xlBook = null;
try {
xlBook = xlApp.Workbooks.Open( @"C:\Documents and
Settings\fprevost\Mes documents\Classeur_test_PA2003.xls",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value );
try {
( (Excel._Worksheet) xlBook.Sheets[1] ).Copy( Missing.Value,
xlBook.Sheets[2] );
}
catch ( Exception ex ) {
System.Console.Out.WriteLine( ex.Message );
System.Console.Out.WriteLine( ex.StackTrace );
}
System.Console.In.ReadLine();
}
finally {
if ( xlBook != null ) {
xlBook.Close( false, Missing.Value, Missing.Value );
xlBook = null;
}
}
}
catch ( Exception ex ) {
System.Console.Out.WriteLine( ex.Message );
System.Console.Out.WriteLine( ex.StackTrace );
System.Console.In.ReadLine();
}
finally {
if ( xlApp != null ) {
xlApp.Quit();
xlApp = null;
GC.Collect();
}
}
}
}
}
=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-==-=-=-=-
Can anybody try to complie and run successfully this code ? or explain me
why that goes wrong ?
Thanks in advance for any help.