When I recently processed the Excel saved by Farpoint, I found that there were various problems with the table style. below is how to modify the Excel format to operate on the content and take notes :)
/// <Summary>
/// Excel table operations
/// </Summary>
/// <Param name = "firstpath"> path of the first Excel table </param>
/// <Param name = "secondpath"> path of the second Excel table </param>
Private void exceloperation (string firstpath, string secondpath)
{
Try
{
Microsoft. Office. InterOP. Excel. Application APP = new Microsoft. Office. InterOP. Excel. Application ();
Microsoft. office. interOP. excel. workbook fworkbook = app. workbooks. open (firstpath, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing );
Microsoft. office. interOP. excel. workbook sworkbook = app. workbooks. open (secondpath, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing );
App. displayalerts = false; // The operation prompt is blocked.
Try
{
(Microsoft. Office. InterOP. Excel. worksheet) sworkbook. Sheets [1]). Delete (); // Delete the first sheet of the second table
Sworkbook. Save ();
Microsoft. Office. InterOP. Excel. worksheet sheet = (Microsoft. Office. InterOP. Excel. worksheet) fworkbook. Sheets [1]; // obtain the first sheet of the first table
Sheet. unprotect (type. Missing); // cancel worksheet Protection
Microsoft. Office. InterOP. Excel. Range = (Microsoft. Office. InterOP. Excel. Range) sheet. Rows [1, type. Missing]; // obtain the first row
Sheet. Activate ();
App. activewindow. freezepanes = false; // unfreeze
App. activewindow. splitcolumn = 0;
App. activewindow. splitrow = 0;
Range. Interior. colorindex = 0; // you can specify that the first row is white.
Range. Delete (Microsoft. Office. InterOP. Excel. xldirection. xldown); // Delete the first row.
Sheet. Copy (sworkbook. Sheets [1], type. Missing); // copy to the second table
Sworkbook. Save ();
}
Catch (exception ex)
{
}
Finally
{
Fworkbook. Close (false, firstpath, null );
System. runtime. interopservices. Marshal. releasecomobject (fworkbook );
Fworkbook = NULL;
Sworkbook. Close (false, secondpath, null );
System. runtime. interopservices. Marshal. releasecomobject (sworkbook );
Sworkbook = NULL;
App. Quit ();
System. runtime. interopservices. Marshal. releasecomobject (APP );
}
}
Catch (exception ex)
{
}
}