2009-10-12 52 views
1

试图编辑我的文件与MyXls:MyXls LIB不修改现有的文件

 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 

似乎MyXLs不能写入我的文件;示例仅用于创建新文件。如果是这样,用这个lib将一个xls文件的所有内容复制到另一个文件中的最好方法是什么?

回答

1

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