简体   繁体   English

SpreadsheetLight从单元格公式获取数值

[英]SpreadsheetLight get numeric value from cell formula

Does anyone know if it possible to retrieve the numeric value of a formula in SpreadsheetLight? 有谁知道是否可以在SpreadsheetLight中检索公式的数值? if not is possible to read the formula in OpenXml as numeric? 是否无法读取OpenXml中的公式为数字?

I need to return 7.07 for cellValue(8,1) 我需要为cellValue(8,1)返回7.07

  public static void TestSlWorkbook()
  {
     SLDocument sl = new SLDocument();
     sl.SetCellValue(1, 1, 1.01);
     sl.SetCellValue(2, 1, 1.01);
     sl.SetCellValue(3, 1, 1.01);
     sl.SetCellValue(4, 1, 1.01);
     sl.SetCellValue(5, 1, 1.01);
     sl.SetCellValue(6, 1, 1.01);
     sl.SetCellValue(7, 1, 1.01);

     sl.SetCellValue(8, 1, "=Sum(A1:A7)");

  }

SpreadsheetLight doesn't have a calculation engine, so there's no evaluation of cell formulas (as of current status). SpreadsheetLight没有计算引擎,因此无法评估单元格公式(以当前状态为准)。 The values you get are either what Excel has calculated previously (which means it's probably outdated by the time you want the value) or 0 (because SpreadsheetLight has no calculation engine, so it defaults to either 0 or empty string). 您获得的值要么是Excel先前计算的值(这意味着到您想要的值时它可能已过时),要么是0(因为SpreadsheetLight没有计算引擎,因此默认为0或空字符串)。

Disclosure: I wrote SpreadsheetLight. 披露:我写了SpreadsheetLight。

SpreadsheetLight has pretty good documentation on their site (as a chm download). SpreadsheetLight在其站点上有相当不错的文档(以chm下载)。 It did not work right for me, so I unzipped it and accessed the html files directly (a chm is a fancy type of zip file). 它不适用于我,因此我将其解压缩并直接访问html文件(chm是一种奇特的zip文件)。

Have you tried sl.GetCellValueAsDouble or any other method of SLDocument? 您是否尝试过sl.GetCellValueAsDouble或SLDocument的任何其他方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM