Reputation: 227
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;
}
Upvotes: 1
Views: 404
Reputation: 3212
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;
}
Upvotes: 1