Background:
In the project, the need to manipulate the Excel document, this thought is OBA application, but it is not. OBA is embedding the. NET application plug-in in Excel, and we need to manipulate excel in SCSF.
I surveyed a little, mainly found 3 ways.
1: Use Microsoft.Office.Interop.Excel, invoke Excel COM components, manipulate Excel files
2: Use OLE DB to manipulate Excel data sources, and then use Ado.net.
3: Use the open XML to access the Excel ZIP file and use DOM.
Realize:
1: Calling com using. NET
////////////////////////
private static Microsoft.Office.Interop.Excel.Application Xapp
...
if (Xapp = null)
Xapp = new Microsoft.Office.Interop.Excel.ApplicationClass ();
Microsoft.Office.Interop.Excel.Workbook xbook = null;
Xapp.visible = false;
Try
{
Xbook = Xapp.workbooks._open (@ "C:\ pending pay. xlsx", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet Xsheet = (Microsoft.Office.Interop.Excel.Worksheet) xbook.sheets[1];
//excel.worksheet xsheet= (excel.worksheet) Xapp.activesheet;
//microsoft.office.interop.excel.range rng1 = Xsheet.get_range ("A1", Type.Missing);
Microsoft.Office.Interop.Excel.Range cell = (Microsoft.Office.Interop.Excel.Range) xsheet.cells[2, 1];
String str = "";
for (int i = 2; cell. Value2!= null; i++)
{
str + = cell. Value2.tostriNg () + ".";
cell = (Microsoft.Office.Interop.Excel.Range) xsheet.cells[2, I];
}
MessageBox.Show (str);
Xbook.close (Microsoft.Office.Interop.Excel.XlSaveAction.xlDoNotSaveChanges, @ "C:\ wages to be paid. xlsx", Missing.Value);
Xapp.quit ();
}
catch (Exception ex)
{
Console.WriteLine (ex. Message.tostring ());
}
///////////////////////