Recently, you need to open an Excel file template and then fill in the data.
When I started to use oledb to connect to the Excel file, an error always occurred, "an updatable..."
Http://expert.csdn.net/Expert/topic/2992/2992809.xml? Temp =. 4825403.
If access is incorrect, most of the errors are caused by permissions, but what I do is that the winform permission is admin.
Unsuccessful
Later, I used ODBC to test several fields.
Start writing Program Then the two cells are found to be disobedient, prompting a parameter error.
Depressing
Http://expert.csdn.net/Expert/topic/3000/3000113.xml? Temp =. 3331262.
Still unsuccessful
No way to Google
Obtain
Http://www.c-sharpcorner.com/winforms/ExcelReadMG.asp
It is feasible to use COM components. This morning, I asked a netizen PM about how to solve the problem.
Write it here,
The following sections Code To add com references
...........
String strfilename = environment. currentdirectory + @ "\ template. TPL ";
String strsavefilename = environment. currentdirectory + @ "\ Excel \" + system. datetime. now. tostring (). replace (":",""). replace ("-",""). replace ("", "") + @". xls ";
Excel. Application thisapplication = new excel. applicationclass ();
Excel. Workbook thisworkbook;
Object missing = system. reflection. Missing. value;
Try
{
// Load the Excel template file
Thisworkbook = thisapplication. workbooks. Open (strfilename, missing, missing );
Excel. worksheet thissheet = (Excel. worksheet) thisworkbook. Sheets [1];
Thissheet. cells [7,1] = dtend. to1_datestring ();
Progressbar. value = 30;
Thisapplication. Visible = false;
Datarow DR = DT. Rows [0];
For (INT I = 0; I {
Thissheet. cells [7, I + 2] = Dr [I]. tostring ();
Progressbar. Value + = 1;
}
// Save the updated data as a new file
Thissheet. saveas (strsavefilename, missing, missing );
}
Catch {}
Finally
{
Thisapplication. Quit ();
Thisworkbook = NULL;
Thisapplication = NULL;
// DT = NULL;
}
Try
{// Open the generated Excel File
Excel. Workbook newworkbook;
Newworkbook = newapplication. workbooks. Open (strsavefilename, missing, missing );
Excel. worksheet newsheet = (Excel. worksheet) newworkbook. Sheets [1];
Newapplication. Visible = true;
// You can also use system. Diagnostics. process. Start (strsavefilename); to open a new file.
}
An Excel process exists in the process after opening the Excel file.
Manual cleanup required
Refer to this articleArticle
Http://www.eggheadcafe.com/articles/20021012.asp
Http://www.aspxboy.com/476/archive.aspx