3

任何人都知道是否有任何方法可以使用 excellibrary 修改 .xls 文件?解释更多:-我正在开发一个应该生成 .xls 文件的项目,从文件中读取,修改并保存它。我设法生成、读取和保存文件,但是每当我尝试修改文件时,它都会生成一个只有修改后的值的新工作表。我使用了以下代码的不同版本

            string filename = string.Format("{0}.xls", rapportDatum);
        using (var file = appStorage.OpenFile(filename,FileMode.OpenOrCreate,FileAccess.ReadWrite))
        {
            using (Stream sr = (file))
            {
                //Converting the Day string to day number as int d
                int d = Int32.Parse(Day);
                // create an instance of excel workbook
                Workbook workbook = new Workbook(); // even used this code WorkBook workbook=Workbook.Open(file); look at sheet now
                // create a worksheet object
                string date = DateTime.Now.ToString("MMMM");
                string sheetName = string.Format("{0}", char.ToUpper(date[0]) + date.Substring(1));
                Worksheet worksheet = new Worksheet(sheetName); // Worksheet worksheet=workbook.worksheets[0]
                // write data in worksheet cells
                worksheet.Cells[0, 0].Value = ("Datum");
                worksheet.Cells[0, 1].Value = ("Avdelning");
                worksheet.Cells[0, 2].Value = ("Allvarlighetsgraden");
                worksheet.Cells[0, 3].Value = ("Raport");
                worksheet.Cells[d, 0].Value = (d);
                worksheet.Cells[d, 1].Value = ("KAVA");
                worksheet.Cells[d, 2].Value = (UsersValue);
                worksheet.Cells[d, 3].Value = (textBox1.Text);
                workbook.Worksheets.Add(worksheet); // Even removed this and workbook.Save(sr) but still the same problem.
                workbook.Save(sr);
            }
        } 

这个烦人的问题有什么解决办法吗?我应该换成另一个excel库吗?在这种情况下有什么建议吗?

你的

4

0 回答 0