Interact with Excel in Cell level
2009-10-19 19:12
274 查看
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Workbooks.Open(oldPath, Missing.Value, 1, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Workbook wb = app.ActiveWorkbook;
Worksheet ws = (Worksheet)wb.ActiveSheet;
ws.Columns.AutoFit();
//ws.Cells.get_Range(ws.Cells[1, 1], ws.Cells[1, 2]).Merge(false);
ws.SaveAs(newPath, XlFileFormat.xlExcel9795, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value);
app.Workbooks.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
ws = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
app.Workbooks.Open(oldPath, Missing.Value, 1, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Workbook wb = app.ActiveWorkbook;
Worksheet ws = (Worksheet)wb.ActiveSheet;
ws.Columns.AutoFit();
//ws.Cells.get_Range(ws.Cells[1, 1], ws.Cells[1, 2]).Merge(false);
ws.SaveAs(newPath, XlFileFormat.xlExcel9795, Missing.Value, Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value);
app.Workbooks.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
ws = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
相关文章推荐
- 删除cell时 报错 Assertion failure in -[UITableView _endCellAnimationsWithContext:]
- Editing Null Data Values in a Cell with JavaFX 2
- How to Create Cross-Cell Bar in Excel
- Assertion failure in -[UITableView _endCellAnimationsWithContext:]---错误
- Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'Multibyte function overloading in
- How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET(利用Ado.net导出到Excel)
- Find Blank Cell in Excel
- CareerCup Fill the array with product of all numbers except the number in that cell
- Get ColumnLetter by ColumnNumber in Excel with VBA
- vsto in excel 时 选中一个cell进入编辑状态 其他操作出错
- how to interact with java object in cpp
- PowerShell: Interact with SharePoint in the fastest way possible
- Use expect command to interact with mysql in linux system
- Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
- Read the sheets in the Excel with QT
- Q6:关于xcode TableView使用Nib文件出现Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:错误
- Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
- Export to Excel with multiple worksheets in visualforce
- data manipulate in excel with easyExcel class
- Working with Excel Files in Python