带公式的excel列不会导入到datatable中

时间:2014-03-07 23:34:34

标签: excel aspose

我使用aspose插入一个新列,并为该列添加了MID公式,然后在本地保存。它按预期工作,但是当我再次尝试检索此文件并尝试将其存储在数据表中时,带有MID公式的新列显示为空白。出于测试目的,我再次完成了该过程,并使用不同的公式(如SUM)对其进行了测试,并且工作正常。好像它不喜欢MID公式。有人知道解决方法吗?

1 个答案:

答案 0 :(得分:0)

我是Aspose的社交媒体开发人员。上述问题已在Aspose.Cells for .NET v8.0.0的最新版本中得到修复。以下是供参考的示例代码:

Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue("Full Name");

//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue("First Last");

//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue("First Last");

//Adding a sample value to "A4" cell
worksheet.Cells["A4"].PutValue("First Last");

//Adding a sample value to "A5" cell
worksheet.Cells["A5"].PutValue("First Last");

//Adding a sample value to "A6" cell
worksheet.Cells["A6"].PutValue("First Last");


//Adding a sample value to "A7" cell
worksheet.Cells["A7"].PutValue("First Last");

//Adding a sample value to "A8" cell
worksheet.Cells["A8"].PutValue("First Last");

//Adding a sample value to "A9" cell
worksheet.Cells["A9"].PutValue("First Last");

//Adding a sample value to "A10" cell
worksheet.Cells["A10"].PutValue("First Last");

int newColPos = worksheet.Cells.MaxColumn + 1;

worksheet.Cells.InsertColumn(newColPos);

string colName = CellsHelper.ColumnIndexToName(newColPos);

string fullNameCol = CellsHelper.ColumnIndexToName(0);

string formula = "=MID(" + fullNameCol + ":" + fullNameCol + ", FIND(" + "\"" + " \"" + "," + fullNameCol + ":" + fullNameCol + "), LEN(" + fullNameCol + ":" + fullNameCol + "))";

colName = colName + "2"; //get second row (skip header row)

worksheet.Cells[colName].SetSharedFormula(formula, 5, 1);

workbook.CalculateFormula();

//Save the workbook for checking
workbook.Save(@"C:\Data\out.xlsx");

System.Data.DataTable dataTable = new System.Data.DataTable();

dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.MaxRow, worksheet.Cells.MaxColumn + 1, true); 

由于此问题仍未得到答复,希望此回复可以帮助任何面临类似问题的人。