ClosedXML Sheet 未更新

ClosedXML Sheet not being updated

我正在尝试使用 ClosedXML 在 C# 中更新 sheet,但 sheet 似乎没有更新。

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 的 InsertData() 方法使用任何 IList<T> 作为输入,而不是字符串或类似对象。 因此,只需使用 List<string>string[] 数组作为要插入的数据的容器。

更新方法:

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;

}