Function Description: insert the first sheet in excel.xlsto the last 2nd pages of excel2.xls.
I used to write a com control in delphi and call it to asp.net and asp. No problem.
Similarly
The following code is successfully executed in winform:
String SubFile = @ "D: \ My program \ Delphi \ Excel2.xls ";
String MainFile = @ "D: \ My program \ Delphi \ Excel.xls ";
Excel. Application ExcelMainFileApp, ExcelSubFileApp;
Excel. _ Workbook ExcelMainFileWorkbook, ExcelSubFileWorkbook;
Excel. _ Worksheet ExcelMainFileWorksheet, ExcelSubFileWorksheet;
Try
{
ExcelMainFileApp = new Excel. Application ();
ExcelMainFileWorkbook = ExcelMainFileApp. Workbooks. Open (MainFile, Type. Missing,
Type. Missing, Type. Missin
G, Type. Missing, Type. Miss
Ing, Type. Missing );
ExcelMainFileWorksheet = (Excel. _ Worksheet) ExcelMainFileWorkbook. ActiveSheet;
String name = ExcelMainFileWorksheet. Name;
ExcelMainFileWorksheet. Cells. Copy (Type. Missing );
ExcelSubFileApp = new Excel. Application ();
ExcelSubFileWorkbook = ExcelSubFileApp. Workbooks. Open (SubFile, Type. Missing, Typ
E. Missing, Type. Missing, T
Ype. Missing, Type. Missing, Type. Missing
, Type. Missing );
ExcelSubFileWorksheet = (Excel. _ Worksheet) ExcelSubFileWorkbook. Sheets. Add (Exce
LSubFileWorkbook. Sheets [ExcelSubFileWorkbook. Sheets. Count], Type. Missing, Type
. Missing, Type. Missing );
ExcelSubFileWorksheet. Paste (Type. Missing, Type. Missing );
Foreach (Excel. Workbook book in ExcelSubFileApp. Workbooks)
{
Book. Save ();
}
ExcelMainFileApp. Workbooks. Close ();
ExcelSubFileApp. Workbooks. Close ();
ExcelMainFileApp. Quit ();
ExcelSubFileApp. Quit ();
}
Catch (Exception theException)
{
}
Finally
{
}
Today, I want to migrate data to asp.net without using com written by delphi. The same is true for winform of code. At the same time
Set the excel permission in DCOMCNFG. EXE.
Slave
New Excel. Application (); // There is no case to prove that the dcom permission is set.
To
ExcelMainFileWorksheet. Cells. Copy (Type. Missing); // COPY to the clipboard.
All OK. However
ExcelSubFileWorksheet. Paste (Type. Missing, Type. Missing); // return from the clipboard paste
There is a problem.
Exception in HRESULT: 0x800A03EC
Depressed.
Can I clear the clipboard in winform? Later, when I wrote the above section, I always asked if I wanted to clear it when turning off excel.
Clipboard, of course, it is very happy that the excel process can be turned off after exiting. :) Previously, the process was to be manually killed.