您的位置:首页 > 其它

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: