[英]ClosedXML Sheet not being updated
I'm trying to update a sheet in C# using ClosedXML, but it seems the sheet is not being updated.我正在尝试使用 ClosedXML 更新 C# 中的工作表,但似乎该工作表没有被更新。
public string FeedAndFetchValueFromThirdSheet(List<string> listValueColl, IXLWorksheet worksheetThird)
{
int posTemp = worksheetThird.RowsUsed().Count(); // Value here is 1
string value = "";
foreach (var obj in listValueColl)
{
posTemp++;
worksheetThird.Cell(posTemp, 1).InsertData(obj);
}
int posUpdated = worksheetThird.RowsUsed().Count(); //After updating the sheet the value still remain 1
value = "A"+ (posTemp - listValueColl.Count()) +":A" + posTemp;
return value;
}
ClosedXML's InsertData()
method uses any IList<T>
as input, not a string or similar object. ClosedXML 的
InsertData()
方法使用任何IList<T>
作为输入,而不是字符串或类似的对象。 So, just use List<string>
or string[]
array as container for data, that you want to insert.因此,只需使用
List<string>
或string[]
数组作为要插入的数据的容器。
The updated method:更新的方法:
public string FeedAndFetchValueFromThirdSheet(List<string> listValueColl, IXLWorksheet worksheetThird)
{
int posTemp = worksheetThird.RowsUsed().Count(); // Value here is 1
string value = "";
foreach (var obj in listValueColl)
{
posTemp++;
// Use IList (simple array, list, etc.) as container for data,
// that you want to insert.
string[] rowDataToInsert = { obj };
// Insert created array (not a string).
worksheetThird.Cell(posTemp, 1).InsertData(rowDataToInsert);
}
int posUpdated = worksheetThird.RowsUsed().Count(); //After updating the sheet the value still remain 1
value = "A" + (posTemp - listValueColl.Count()) + ":A" + posTemp;
return value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.