You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SplitAndFreezePanes.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.examples.hssf.usermodel;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import org.apache.poi.hssf.usermodel.HSSFSheet;
  19. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  20. import org.apache.poi.ss.usermodel.Sheet;
  21. public class SplitAndFreezePanes {
  22. public static void main(String[] args) throws IOException {
  23. try (HSSFWorkbook wb = new HSSFWorkbook()) {
  24. HSSFSheet sheet1 = wb.createSheet("new sheet");
  25. HSSFSheet sheet2 = wb.createSheet("second sheet");
  26. HSSFSheet sheet3 = wb.createSheet("third sheet");
  27. HSSFSheet sheet4 = wb.createSheet("fourth sheet");
  28. // Freeze just one row
  29. sheet1.createFreezePane(0, 1, 0, 1);
  30. // Freeze just one column
  31. sheet2.createFreezePane(1, 0, 1, 0);
  32. // Freeze the columns and rows (forget about scrolling position of the lower right quadrant).
  33. sheet3.createFreezePane(2, 2);
  34. // Create a split with the lower left side being the active quadrant
  35. sheet4.createSplitPane(2000, 2000, 0, 0, Sheet.PANE_LOWER_LEFT);
  36. try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {
  37. wb.write(fileOut);
  38. }
  39. }
  40. }
  41. }