Closed xjfnet closed 2 years ago
the file has 26 sheets, the sheet has 585 rows and 123 columns
void Main()
{
var students = new List<Student>();
students.Add(new Student() { Name = "aaa", Age = 1 });
students.Add(new Student() { Name = "aaa", Age = 1 });
students.Add(new Student() { Name = "aaa", Age = 1 });
var file = "test.xlsx";
if (false)
{
var mapper = new Mapper();
mapper.Put(students);
mapper.Save(file);
}
if (true)
{
var mapper = new Mapper(file);
var list = mapper.Take<Student>().Select(x => x.Value).ToList();
list.ForEach(x => x.Age = 4);
mapper.Put(list);
mapper.Save(file);
}
}
public class Student
{
public string Name { get; set; }
public int Age { get; set; }
}
this work's fine, the sheet was overwritten
but for the big xlsx file, i must remove the sheet first, then Put data, like these
var mapper = new Mapper(fileName);
var list = mapper.Task<ClassT>(sheetName).Select(x => x.Value).ToList();
list.ForEach(x => x.Name = "1111111");
mapper.Workbook.RemoveSheetAt(mapper.Workbook.GetSheetIndex(sheetName));
mapper.Put(list, sheetName);
mapper.Save(fileName);
I've tested with multi-sheet and multi-row file, seem works fine.
Please pay attention on the Put
method, you may put into another sheet, if you do not specify sheet name or index it will be the first sheet.
i wirte the program last year, and it work's fine then i update Npoi.Mapper recently, and found the Sheet can not be overwritten i have to remove the sheet first, then put the sheet with the same name and save.
can you upload the file and your code snippet?
closing stale issues
then open the xlsx file, i found the sheet unchanged, new value does not overwirte the old one but a year ago, these code work's fine