DreamNet
DreamNet

Reputation: 627

Modifying excel file using the Lite.ExcelLibrary for silverlight

Anyone knows if there is any way to modify a .xls file using the excellibrary? To explain more:- I'm working on a project that should generate a .xls file, read from the file, modify it and save it. I managed to generate, read and save the file, but whenever i tried to modify the file, it generate a new sheet with only the modified value. I used different version of the below code

            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);
            }
        } 

Is there any work around for this annouying problem? should i change to another excel library? In this case any recommendation?

Yours

Upvotes: 3

Views: 1413

Answers (0)

Related Questions