Asp.net excel Permissions

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.