zoukankan      html  css  js  c++  java
  • excle,aspose.cells 公式字段值取不到 xmls转xml

    问题:

    一,单元格如果是公式的,读出值为0

    aspose.cells 4.4.0.5版本 由于太低,读xmls后缀的excel文件时,发现如果此列是公式算出来的,值是获取不到的。获取到的值一直是0

    二,升级可以解决问题。但会有如下问题

    1,样式使用改动大

    如果升级aspose,此问题可以解决。不过有好多地方要做修改。

    2,转pdf打印有问题

    如果你对aspose生成好的excle转pdf进行打印。会有断页,行自适应方法后,在excle显示正常,但打印出来后显示不全。

    我试了。7.2.1.0版本5.3.1.0版本,版本越高打印越有问题。

    三,解决。

    直接用Microsoft.Office.Interop.Excel.dll 12.0版本就行了。这个东西在增加引用.net里就有。然后用我下面的代码将xmls转成xml就行了。原来的东西不用变

    /// <summary>
            /// 转换Excel格式
            /// </summary>
            /// <param name="strSavePath">原始路径</param>
            /// <returns>新路径</returns>
            public static string ConvertExcel(string strSavePath)
            {
                string strPath = string.Empty;
                //将xml文件转换为标准的Excel格式 
                Object Nothing = System.Reflection.Missing.Value;//由于yongCOM组件很多值需要用Missing.Value代替   
                Excel.Application ExclApp = new Excel.ApplicationClass();// 初始化
                Excel.Workbook ExclDoc = ExclApp.Workbooks.Open(strSavePath, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);//打开Excl工作薄   
                FileInfo exportFile = new FileInfo(strSavePath);
                if (exportFile.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
                {
                    strPath = exportFile.FullName.Replace(exportFile.Extension, ".xls");
                    if (File.Exists(strPath))
                    {
                        File.Delete(strPath);
                    }
                }
                try
                {
                    Object format = Excel.XlFileFormat.xlWorkbookNormal;//获取Excl 2007文件格式   这个不用管,就用这个,换成其他可能不行。
                    ExclApp.DisplayAlerts = false;
                    ExclDoc.SaveAs(strPath, format, Nothing, Nothing, Nothing, Nothing, Excel.XlSaveAsAccessMode.xlExclusive, Nothing, Nothing, Nothing, Nothing, Nothing);//保存为Excl 2007格式   
                }
                catch (Exception ex) { }
                ExclDoc.Close(Nothing, Nothing, Nothing);
                ExclApp.Quit();
                return strPath;
            }
    转换Excel格式


     

  • 相关阅读:
    「SDOI2009」Bill的挑战
    「HAOI2011」Problem c
    HDU3530【STL/单调队列/RMQ】
    HDU2874【倍增、ST】
    POJ2955【区间DP】
    SPOJ375 Query on a tree 【倍增,在线】
    训练[2]-DFS
    Fighting For 2017 Season Contest 1
    POJ2796/DP/单调栈
    New Year Tree 【DFS序+线段树区间查询修改+二进制保存状态】
  • 原文地址:https://www.cnblogs.com/xbding/p/4586883.html
Copyright © 2011-2022 走看看