批量转换Excel 2003的格式到 Excel 2007或2010的格式
代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> /// <summary>
/// 批量转换Excel 2003 至Excel 2007/2010格式
/// 可以修改XlFileFormat枚举的值来转换为想要的格式
/// </summary>
/// <param name="v_strDir">工作簿的查找路径</param>
private static void fn批量转换Excel文件格式(string v_strDir)
{
Application app = new Application();
DirectoryInfo dir = new DirectoryInfo(v_strDir);
Workbook book;
app.Application.DisplayAlerts = false;
try
{
foreach (FileInfo fi in dir.GetFiles("*.xls", SearchOption.AllDirectories))
{
book = app.Workbooks.Open(fi.FullName);
book.SaveAs(fi.DirectoryName + @"\" + fi.Name.Replace(fi.Extension, string.Empty) + ".xlsx", XlFileFormat.xlOpenXMLWorkbook);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
app.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
GC.Collect();
}
}