簡體   English   中英

使用epplus將Excel保存為電子表格XML 2003

[英]Saving excel as spreadsheet xml 2003 with epplus

我正在使用EPPlus。

但是文件類型存在問題,因為在我工作的地方,我們使用的管理系統僅將SpreadSheet XML 2003讀取為excel文件。

我嘗試將文檔另存為XML,但未獲得SpreadSheet XML 2003 Excel格式

var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CodigoInteligente", "Articulos.xml");
var archivo = new FileInfo(path);

如何使用帶有epplus的XML電子表格XML 2003格式生成Excel? 或我可以使用哪個圖書館?

我不想使用此解決方案,因為它使用的是Microsoft.Office.Interop並且並非所有計算機都已安裝excel,但是,我回答了這個問題,因為在我的情況下有人會用到。

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook book = null;
bool status = false;
try 
    { 
    var originalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CodigoInteligente" , "Originales" , "Articulos.xls");
    var oldFile = new FileInfo(originalPath);
    if (!oldFile.Exists)
        {
            return false;
        }
    var newPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CodigoInteligente", "Articulos.xls");
    var newFile = new FileInfo(newPath);
    if (newFile.Exists)
        {
        if (IsFileLocked(newFile))
            {
                return false;
            }
        newFile.Delete();
        }
    book = xlApp.Workbooks.Open(originalPath);
    book.SaveAs(newPath, Microsoft.Office.Interop.Excel.XlFileFormat.xlXMLSpreadsheet);
    status = true;
    }
    catch(Exception ex)
    {
        System.Windows.Forms.MessageBox.Show("Hubo un error");
        Logs.agregarLog(ex);
        return false;
    }
    finally
        {                
        book.Close(false);
        xlApp.Quit();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
        }
return status;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM