【问题标题】:Altering spreadsheet causes loss of formatting更改电子表格会导致格式丢失
【发布时间】:2015-03-24 05:17:17
【问题描述】:

我在使用 excel 时使用 excellibrary 库。我的代码是

        Workbook book = Workbook.Load(book_name);
        Workbook book_new = Workbook.Load(file_name);

        Worksheet sheet = book.Worksheets[0];
        Worksheet sheet_new = book_new.Worksheets[0];

        for (int rowIndex = 7; rowIndex <= 2235; rowIndex++)
        {
            Console.WriteLine(sheet.Cells[rowIndex, ost_index] + " " + sheet_new.Cells[rowIndex, ost_index]);

            sheet.Cells[rowIndex, ost_index] = sheet_new.Cells[rowIndex, ost_index];
            sheet.Cells[rowIndex, price_index] = sheet_new.Cells[rowIndex, price_index];
        }

        book.Save(book_name);

在这段代码中,我将两个列从一个文件复制到另一个文件。还有一个问题。这个 excel 文件有很多样式,如超链接等。当我在使用程序后打开文件时,我看到一个带有文本 无法读取文件的窗口。单击“确定...确定...确定...”后,我看到没有格式的文件(没有颜色,没有样式等)。我该如何修复它? 附言对不起我的英语。

【问题讨论】:

  • 你正在保存这本书..但是你在哪里关闭和处理创建的对象..?
  • 你能写出怎么做吗?
  • 你前面有写的代码你熟悉如何调试和使用Intellesense
  • 对不起,我不明白:我应该在这里关闭和丢弃哪个对象?
  • 你有方法 Workbook.Close() 或 dispose 吗?在保存调用之后为 Workbook 的两个实例调用它。

标签: c# .net excel


【解决方案1】:

这似乎是库中已知的bug,并且由于自报告以来该库尚未更新,此时最好的选择是切换到另一个库。

【讨论】:

    猜你喜欢
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 2019-01-29
    • 2018-05-16
    • 2022-12-05
    • 1970-01-01
    相关资源
    最近更新 更多