Excelize冻结行生成带错误的文件

问题描述

我正在尝试冻结工作表的第一行和前两列。

xlsx.SetPanes(sheetName,`{"freeze":true,"x_split":2,"y_split":1,"top_left_cell":"A1","active_pane":"topLeft","panes":[{"sqref":"A1:B1","pane":"topLeft"},{"sqref":"C1:XFD1","pane":"topRight"},{"sqref":"A2:B2","pane":"bottomLeft"},{"sqref":"C3:XFD3","pane":"bottomright"}]}`)

如果我在excel中打开文件,则会收到以下警报,并在尝试恢复恢复日志后未删除任何内容

警告:

We found a problem with some content in ’test.xlsx’. Do you want us to try to recover as much as we can? If you trust the source of this workbook,click Yes.

恢复日志:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
         <logFileName>Repair Result to test3.xml</logFileName>
         <summary>Errors were detected in file ’/test.xlsx’</summary>
         <repairedRecords summary="Following is a list of repairs:">
             <repairedRecord>Repaired Records: View from /xl/worksheets/sheet1.xml part</repairedRecord>
         </repairedRecords>
      </recoveryLog>

这不是数据的问题,因为如果我删除setPanes方法文件可以正常工作。我在做什么错了?

还请注意,如果我使用Google表格打开文件,则可以正常工作。

解决方法

我终于弄清楚了

xlsx.SetPanes(sheetName,`{"freeze":true,"x_split":2,"y_split":1,"top_left_cell":"C2","active_pane":"bottomRight","panes":[{"pane":"topLeft"},{"pane":"topRight"},{"pane":"bottomLeft"},{"active_cell":"C2","sqref":"C2","pane":"bottomRight"}]}`)
,

这是另一个示例。在第一列和前三行中设置冻结:

const checkedCount = Object.values(checkedValues).length; // existing
const checkedCount = Object.values(checkedValues).filter(item=>item==true).length //replace with this line

密钥似乎确定您的xlsx.SetPanes(sheet,` { "freeze":true,"x_split":1,"y_split":3,"top_left_cell":"B4","panes":[ {"pane":"topLeft"},{"active_cell":"B4","sqref":"B4","pane":"bottomRight"} ] } `) x_split值和y_split的位置。有点挣扎,但为作者找出答案提供了支持。