在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
string filePath = this.openFileDialog1.FileName; OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ filePath + ";Extended Properties=\"Excel 8.0;\""); conn.Open(); //建立Excel应用(写Excel Sheet之前)
Microsoft.Office.Interop.Excel.ApplicationClass oExcel; oExcel = new Microsoft.Office.Interop.Excel.ApplicationClass(); oExcel.UserControl = false; Microsoft.Office.Interop.Excel.WorkbookClass wb = (Microsoft.Office.Interop.Excel.WorkbookClass)oExcel.Workbooks.Add(System.Reflection.Missing.Value); //新建一个Sheet,新建后会默认处于焦点状态
wb.Worksheets.Add(Missing.Value, Missing.Value, 1, Missing.Value);
//写单元格示例
oExcel.Cells[1, 1] = "第一列";
oExcel.Cells[1, 2] = "第二列"; oExcel.Cells[1, 3] = "第三列"; //保存工作簿
wb.Saved = true;
//生成文件,释放资源
oExcel.ActiveWorkbook.SaveCopyAs(filename);
oExcel.Quit(); System.GC.Collect(); |
请发表评论