[]
        
(Showing Draft Content)

设置尾部冻结行/列

GcExcel允许用户设置尾部冻结行/列。尾部冻结对应于工作表最底部和最右侧的行和列。因此,它允许用户在滚动工作表的其余部分时保持这些特定的行或列可见。

然而,尾部冻结行/列仅在通过执行JSON导入导出与SpreadJS交互时可见,在Excel或PDF中不生效。

尾部冻结行/列

可以使用IWorksheet接口的freezeTrailingPanes方法设置尾部冻结行/列,该方法以行和列的位置为参数。冻结的行数和列数也可以分别使用 getFreezeTrailingRow getFreezeTrailingColumn 方法进行检索。

请参阅以下示例代码以设置尾部冻结行/列并检索工作表中尾部冻结的行数和列数。

// Create a new workbook
Workbook workbook = new Workbook();

// Use sheet index to get worksheet.
IWorksheet worksheet = workbook.getWorksheets().get(0);

// Freeze trailing pane
worksheet.freezeTrailingPanes(2, 3);

System.out.println("Number of trailing rows are: " + worksheet.getFreezeTrailingRow()
        + "\nNumber of trailing columns are: " + worksheet.getFreezeTrailingColumn());

// Save workbook to ssjson
String json = workbook.toJson();
try {
    BufferedWriter out = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream("FreezeTrailingRowsCols.ssjson"), "utf-8"));
    out.write(json);
    out.flush();
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}

解冻尾部冻结行/列

类似地,可以使用IWorksheet接口的 unfreezeTrailingPanes 方法解冻尾部冻结行/列。

请参阅以下示例代码以解冻尾部冻结行/列。

// Create a new workbook
Workbook workbook = new Workbook();

// Use sheet index to get worksheet.
IWorksheet worksheet = workbook.getWorksheets().get(0);

// Freeze trailing pane
worksheet.freezeTrailingPanes(2, 3);

// Unfreeze trailing pane
worksheet.unfreezeTrailingPanes();

// Save workbook to ssjson
String json = workbook.toJson();
try {
    BufferedWriter out = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream("UnFreezeTrailingRowsCols.ssjson"), "utf-8"));
    out.write(json);
    out.flush();
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}