开发者

MyXls lib doesn't edit existing file

开发者 https://www.devze.com 2022-12-08 20:30 出处:网络
Trying to edit my file with MyXls: XlsDocument doc = new XlsDocument(InputFilePath); Worksheet sheet =开发者_开发问答 doc.Workbook.Worksheets[InputSheet.Substring(0, InputSheet.Length - 1)];

Trying to edit my file with MyXls:

        XlsDocument doc = new XlsDocument(InputFilePath);

        Worksheet sheet =开发者_开发问答 doc.Workbook.Worksheets[InputSheet.Substring(0, InputSheet.Length - 1)];

        foreach (var row in sheet)
        {
            if (row.CellCount > 1)
            {
                Cell firstCell = row.GetCell(1);
                firstCell.Font.Weight = FontWeight.Bold;
            }
        }
        doc.Save();//Here is a nullreference Exception without any explanations

It seems that MyXLs cannot write into my file; example is for creating new file only. If so, what is the best way to copy all the contents of one xls file into another with this lib?


FileStream file = new FileStream(inputFilePath, FileMode.Create, FileAccess.Write);
doc.Save(file);
file.Close();

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号