简体   繁体   中英

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.

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. So, just use List<string> or string[] array as container for data, that you want to insert.

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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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