This project is read-only.

excel data corruption

Apr 26, 2013 at 7:50 AM
Edited Apr 26, 2013 at 7:52 AM
Read xlsx template , modify xlsx data, then save to excel file, and then open saved xlsx file ; Excel program will prompt repair data, opened excel file format and content have changed
 OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "excel file *.xlsm|*.xlsm";

            if (dialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            FileStream fileStream = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read);
            IWorkbook workbook = WorkbookFactory.Create(fileStream);

            ISheet ProcessSheet = workbook.GetSheet("sheet1");

            ProcessSheet.ShiftRows(9, ProcessSheet.LastRowNum, 10, true, false);

            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "Excel file *.xlsm|*.xlsm";
            if (saveDialog.ShowDialog() == DialogResult.Cancel)
                return;

            FileStream WirteStream = new FileStream(saveDialog.FileName, FileMode.OpenOrCreate, FileAccess.Write);
            workbook.Write(WirteStream);
            WirteStream.Close();
            fileStream.Close();