【问题标题】:Saving excel as spreadsheet xml 2003 with epplus使用epplus将excel保存为电子表格xml 2003
【发布时间】:2018-08-08 16:22:17
【问题描述】:

我正在使用 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 2003 格式的 Excel?或者我可以使用哪个库?

【问题讨论】:

  • 你的意思是xlx吗? Xml 与 Excel 有很大不同。
  • 我认为 EPPLus 不会编写那种格式。但是,如果我查看spec for that SpreadsheetML,我怀疑您可以先将文件保存为 XLSX,然后在xl\worksheets\Sheet1.xml 处读取文件(请记住,xlsx 只是一个 zip 文件),然后应用 XSLT 转换。不是微不足道的,但如果没有其他值得尝试的东西。
  • @jdweng excel 具有旧的 xml 格式
  • @rene 你介意 xslt 转换吗?不明白,谢谢!
  • @SouXin:不是那个帖子的复制品。此问题专门询问有关使用 EPPlus 保存为特定 Excel 版本文件的问题,这与您作为副本(两次)使用的帖子不同。

标签: c# excel xml epplus


【解决方案1】:

我不想使用此解决方案,因为它使用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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    相关资源
    最近更新 更多