C winform Summary of Methods for Opening Excel Documents of Must see Articles

  • 2021-12-04 10:57:49
  • OfStack

C # Open Excel Documentation Method 1: Call the COM component of Excel

Open the Add Reference dialog box in the project, select the COM column, then find "Microsoft Excel 11.0 Object Library" (Office 2003) in the COM list, and add it to the project's References. Visual C #. NET automatically generates the corresponding. NET component file for later normal use.

The click events of the button are as follows:


privatevoid button1_Click(object sender, EventArgs e) 
{ 
 Excel.Application excel = 
 new Excel.Application(); // Quote Excel Object  
 Excel.Workbook book = 
 excel.Application.Workbooks.Add("c:\\test.xls"); 
 // Quote Excel Workbook  
 excel.Visible = true; // Cause Excel Visible  
} 

C # Open Excel Documentation Method 2: Use the Command Line

We enter c in Start → Run:\\ test. xls, and then if the computer has Excel installed, it will automatically open this file. The code is as follows:


privatevoid button1_Click(object sender, EventArgs e) 
{ 
 System.Diagnostics.Process.Start("c:\\test.xls"); 
} 

C # Open Excel document specific method of introduction to you here, I hope you understand and learn C # Open Excel document help.

My 1 point of view:


private void button1_Click(object sender, EventArgs e)    

{      

Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();      

Workbook wkb = app.Workbooks.Add(@"E:\Work\DemoBase_091111\CSharpOpenExcel\cshapropenexcel.xlsx"); 

// Open the existing excel,      

// And through gdal Open the existing shp, The method is       

// OSGeo.GDAL.Gdal.AllRegister();       

// OSGeo.GDAL.Dataset dataSet = OSGeo.GDAL.Gdal.Open(@"E:\Work\DemoBase_091111\GDALTEST\testshapefile\point_out.shp", Access.GA_ReadOnly);       

//2 Those are similar, 1 Personal use add Method, 1 Personal use open Methods, all of which can be carried out under 1 The files and technologies of step operation are identical      

  app.Visible = true;    

}


Related articles: