This project is read-only.

修改xlsx文件后保存会丢失数据和格式

Apr 26, 2013 at 8:05 AM
1读物xlsx文件或xlsm文件
2修改xlsx中的数据然后保存其他文件
3打开保存文件,Excel程序会提示:在文件中发现不可读取的内容。是否恢复此工作薄?如果信任此工作薄的来源,请选择是
4强制信任后打开,发现文件和原文件格式丢失
5上述问题再excel2003中不存在,只在excel2007存在
OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "excel file *.xlsx|*.xlsx";

            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 *.xlsx|*.xlsx";
            if (saveDialog.ShowDialog() == DialogResult.Cancel)
                return;

            FileStream WirteStream = new FileStream(saveDialog.FileName, FileMode.OpenOrCreate, FileAccess.Write);
            workbook.Write(WirteStream);
            WirteStream.Close();
            fileStream.Close();
Coordinator
Oct 10, 2013 at 5:25 AM
请上传你的xlsx文件,谢谢。
Oct 11, 2013 at 6:21 AM
我也碰到同样的问题,xlsx附件怎么上传