git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@707843 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
97ceedbbf7
commit
b09c6e3031
@ -18,25 +18,40 @@ package org.apache.poi.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
public class SetPrintArea {
|
||||
|
||||
/**
|
||||
* How to use newlines in cells
|
||||
*/
|
||||
public class CellNewlines {
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("Sheet1");
|
||||
//wb.setPrintArea(0, "$A$1:$C$2");
|
||||
//sets the print area for the first sheet
|
||||
//Alternatively:
|
||||
wb.setPrintArea(0, 1, 2, 0, 3); //is equivalent to using the name reference (See the JavaDocs for more details)
|
||||
Sheet sheet = wb.createSheet();
|
||||
|
||||
// Create various cells and rows for spreadsheet.
|
||||
Row row = sheet.createRow(2);
|
||||
Cell cell = row.createCell(2);
|
||||
cell.setCellValue("Use \n with word wrap on to create a new line");
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("printArea.xlsx");
|
||||
//to enable newlines you need set a cell styles with wrap=true
|
||||
CellStyle cs = wb.createCellStyle();
|
||||
cs.setWrapText(true);
|
||||
cell.setCellStyle(cs);
|
||||
|
||||
//increase row height to accomodate two lines of text
|
||||
row.setHeightInPoints((2*sheet.getDefaultRowHeightInPoints()));
|
||||
|
||||
//adjust column width to fit the content
|
||||
sheet.autoSizeColumn((short)2);
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("ooxml-newlines.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* Demonstrates various settings avaiable in the Page Setup dialog
|
||||
*/
|
||||
public class WorkingWithPageSetup {
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
|
||||
/**
|
||||
* It's possible to set up repeating rows and columns in your printouts by using the setRepeatingRowsAndColumns() function in the Workbook object.
|
||||
*
|
||||
* This function Contains 5 parameters:
|
||||
* The first parameter is the index to the sheet (0 = first sheet).
|
||||
* The second and third parameters specify the range for the columns to repreat.
|
||||
* To stop the columns from repeating pass in -1 as the start and end column.
|
||||
* The fourth and fifth parameters specify the range for the rows to repeat.
|
||||
* To stop the columns from repeating pass in -1 as the start and end rows.
|
||||
*/
|
||||
Sheet sheet1 = wb.createSheet("new sheet");
|
||||
Sheet sheet2 = wb.createSheet("second sheet");
|
||||
|
||||
// Set the columns to repeat from column 0 to 2 on the first sheet
|
||||
Row row1 = sheet1.createRow(0);
|
||||
row1.createCell(0).setCellValue(1);
|
||||
row1.createCell(1).setCellValue(2);
|
||||
row1.createCell(2).setCellValue(3);
|
||||
Row row2 = sheet1.createRow(1);
|
||||
row2.createCell(1).setCellValue(4);
|
||||
row2.createCell(2).setCellValue(5);
|
||||
|
||||
|
||||
Row row3 = sheet2.createRow(1);
|
||||
row3.createCell(0).setCellValue(2.1);
|
||||
row3.createCell(4).setCellValue(2.2);
|
||||
row3.createCell(5).setCellValue(2.3);
|
||||
Row row4 = sheet2.createRow(2);
|
||||
row4.createCell(4).setCellValue(2.4);
|
||||
row4.createCell(5).setCellValue(2.5);
|
||||
|
||||
// Set the columns to repeat from column 0 to 2 on the first sheet
|
||||
wb.setRepeatingRowsAndColumns(0,0,2,-1,-1);
|
||||
// Set the the repeating rows and columns on the second sheet.
|
||||
wb.setRepeatingRowsAndColumns(1,4,5,1,2);
|
||||
|
||||
// Set the the repeating rows and columns on the second sheet
|
||||
wb.setRepeatingRowsAndColumns(1, 4, 5, 1, 2);
|
||||
|
||||
|
||||
|
||||
//set the print area for the first sheet
|
||||
wb.setPrintArea(0, 1, 2, 0, 3);
|
||||
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("ooxml-printsetup.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
}
|
@ -37,10 +37,22 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
private CTHyperlink ctHyperlink;
|
||||
private String location;
|
||||
|
||||
/**
|
||||
* Create a new XSSFHyperlink. This method is protected to be used only by XSSFCreationHelper
|
||||
*
|
||||
* @param type - the type of hyperlink to create
|
||||
*/
|
||||
protected XSSFHyperlink(int type) {
|
||||
this.type = type;
|
||||
this.ctHyperlink = CTHyperlink.Factory.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a XSSFHyperlink amd initialize it from the supplied CTHyperlink bean and package relationship
|
||||
*
|
||||
* @param ctHyperlink the xml bean containing xml properties
|
||||
* @param hyperlinkRel the relationship in the underlying OPC package which stores the actual link's address
|
||||
*/
|
||||
protected XSSFHyperlink(CTHyperlink ctHyperlink, PackageRelationship hyperlinkRel) {
|
||||
this.ctHyperlink = ctHyperlink;
|
||||
this.externalRel = hyperlinkRel;
|
||||
@ -48,14 +60,14 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
// Figure out the Hyperlink type and distination
|
||||
|
||||
// If it has a location, it's internal
|
||||
if(ctHyperlink.getLocation() != null) {
|
||||
if (ctHyperlink.getLocation() != null) {
|
||||
type = Hyperlink.LINK_DOCUMENT;
|
||||
location = ctHyperlink.getLocation();
|
||||
} else {
|
||||
// Otherwise it's somehow external, check
|
||||
// the relation to see how
|
||||
if(externalRel == null) {
|
||||
if(ctHyperlink.getId() != null) {
|
||||
if (externalRel == null) {
|
||||
if (ctHyperlink.getId() != null) {
|
||||
throw new IllegalStateException("The hyperlink for cell " + ctHyperlink.getRef() + " references relation " + ctHyperlink.getId() + ", but that didn't exist!");
|
||||
} else {
|
||||
throw new IllegalStateException("A sheet hyperlink must either have a location, or a relationship. Found:\n" + ctHyperlink);
|
||||
@ -66,10 +78,10 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
location = target.toString();
|
||||
|
||||
// Try to figure out the type
|
||||
if(location.startsWith("http://") || location.startsWith("https://")
|
||||
if (location.startsWith("http://") || location.startsWith("https://")
|
||||
|| location.startsWith("ftp://")) {
|
||||
type = Hyperlink.LINK_URL;
|
||||
} else if(location.startsWith("mailto:")) {
|
||||
} else if (location.startsWith("mailto:")) {
|
||||
type = Hyperlink.LINK_EMAIL;
|
||||
} else {
|
||||
type = Hyperlink.LINK_FILE;
|
||||
@ -96,7 +108,7 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
* Generates the relation if required
|
||||
*/
|
||||
protected void generateRelationIfNeeded(PackagePart sheetPart) {
|
||||
if(needsRelationToo()) {
|
||||
if (needsRelationToo()) {
|
||||
// Generate the relation
|
||||
PackageRelationship rel =
|
||||
sheetPart.addExternalRelationship(location, XSSFRelation.SHEET_HYPERLINKS.getRelation());
|
||||
@ -106,40 +118,79 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of this hyperlink
|
||||
*
|
||||
* @return the type of this hyperlink
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reference of the cell this applies to,
|
||||
* eg A55
|
||||
* es A55
|
||||
*/
|
||||
public String getCellRef() {
|
||||
return ctHyperlink.getRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file
|
||||
*
|
||||
* @return the address of this hyperlink
|
||||
*/
|
||||
public String getAddress() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return text label for this hyperlink
|
||||
*
|
||||
* @return text to display
|
||||
*/
|
||||
public String getLabel() {
|
||||
return ctHyperlink.getDisplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Location within target. If target is a workbook (or this workbook) this shall refer to a
|
||||
* sheet and cell or a defined name. Can also be an HTML anchor if target is HTML file.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
public String getLocation() {
|
||||
return ctHyperlink.getLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text label for this hyperlink
|
||||
*
|
||||
* @param label text label for this hyperlink
|
||||
*/
|
||||
public void setLabel(String label) {
|
||||
ctHyperlink.setDisplay(label);
|
||||
}
|
||||
|
||||
public void setLocation(String location){
|
||||
/**
|
||||
* Location within target. If target is a workbook (or this workbook) this shall refer to a
|
||||
* sheet and cell or a defined name. Can also be an HTML anchor if target is HTML file.
|
||||
*
|
||||
* @param location - string representing a location of this hyperlink
|
||||
*/
|
||||
public void setLocation(String location) {
|
||||
ctHyperlink.setLocation(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file
|
||||
*
|
||||
* @param address - the address of this hyperlink
|
||||
*/
|
||||
public void setAddress(String address) {
|
||||
location = address;
|
||||
//we must set location for internal hyperlinks
|
||||
if(type == Hyperlink.LINK_DOCUMENT){
|
||||
if (type == Hyperlink.LINK_DOCUMENT) {
|
||||
setLocation(address);
|
||||
}
|
||||
}
|
||||
@ -155,20 +206,50 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
return new CellReference(ctHyperlink.getRef());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the column of the first cell that contains the hyperlink
|
||||
*
|
||||
* @return the 0-based column of the first cell that contains the hyperlink
|
||||
*/
|
||||
public int getFirstColumn() {
|
||||
return buildCellReference().getCol();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the column of the last cell that contains the hyperlink
|
||||
*
|
||||
* @return the 0-based column of the last cell that contains the hyperlink
|
||||
*/
|
||||
public int getLastColumn() {
|
||||
return buildCellReference().getCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the row of the first cell that contains the hyperlink
|
||||
*
|
||||
* @return the 0-based row of the cell that contains the hyperlink
|
||||
*/
|
||||
public int getFirstRow() {
|
||||
return buildCellReference().getRow();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the row of the last cell that contains the hyperlink
|
||||
*
|
||||
* @return the 0-based row of the last cell that contains the hyperlink
|
||||
*/
|
||||
public int getLastRow() {
|
||||
return buildCellReference().getRow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the column of the first cell that contains the hyperlink
|
||||
*
|
||||
* @param col the 0-based column of the first cell that contains the hyperlink
|
||||
*/
|
||||
public void setFirstColumn(int col) {
|
||||
ctHyperlink.setRef(
|
||||
new CellReference(
|
||||
@ -176,9 +257,21 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
).formatAsString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the column of the last cell that contains the hyperlink
|
||||
*
|
||||
* @param col the 0-based column of the last cell that contains the hyperlink
|
||||
*/
|
||||
public void setLastColumn(int col) {
|
||||
setFirstColumn(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the row of the first cell that contains the hyperlink
|
||||
*
|
||||
* @param row the 0-based row of the first cell that contains the hyperlink
|
||||
*/
|
||||
public void setFirstRow(int row) {
|
||||
ctHyperlink.setRef(
|
||||
new CellReference(
|
||||
@ -186,6 +279,12 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
).formatAsString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the row of the last cell that contains the hyperlink
|
||||
*
|
||||
* @param row the 0-based row of the last cell that contains the hyperlink
|
||||
*/
|
||||
public void setLastRow(int row) {
|
||||
setFirstRow(row);
|
||||
}
|
||||
|
@ -589,6 +589,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
if (name == null) return null;
|
||||
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
|
||||
return name.getReference();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -697,19 +698,52 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
return getPackagePart().getContentType().equals(XSSFRelation.MACROS_WORKBOOK.getContentType());
|
||||
}
|
||||
|
||||
public void removeName(int index) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
/**
|
||||
* removes the name
|
||||
*
|
||||
* @param nameIndex name index
|
||||
*/
|
||||
public void removeName(int nameIndex) {
|
||||
if (namedRanges.size() > nameIndex) {
|
||||
XSSFName name = getNameAt(nameIndex);
|
||||
int cont = 0;
|
||||
for (XSSFName nameRange : namedRanges) {
|
||||
if (nameRange.getReference().equals(name.getReference())) {
|
||||
namedRanges.remove(cont);
|
||||
getDefinedNames().removeDefinedName(nameIndex);
|
||||
break;
|
||||
}
|
||||
cont++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the name
|
||||
*
|
||||
* @param name range
|
||||
* name index
|
||||
*/
|
||||
public void removeName(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
//TODO
|
||||
//int index=getNameIndex(name);
|
||||
//removeName(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the printarea for the sheet specified
|
||||
*
|
||||
* @param sheetIndex 0-based sheet index (0 = First Sheet)
|
||||
*/
|
||||
public void removePrintArea(int sheetIndex) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
int cont = 0;
|
||||
for (XSSFName name : namedRanges) {
|
||||
if (name.getNameName().equals(XSSFName.BUILTIN_PRINT_AREA) && name.getLocalSheetId() == sheetIndex) {
|
||||
namedRanges.remove(cont);
|
||||
break;
|
||||
}
|
||||
cont++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -818,6 +852,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
name = createBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
|
||||
namedRanges.add(name);
|
||||
}
|
||||
//short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
|
||||
//name.setExternSheetNumber(externSheetIndex);
|
||||
name.setReference(reference);
|
||||
}
|
||||
|
||||
@ -835,12 +871,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
setPrintArea(sheetIndex, reference);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the repeating rows and columns for a sheet.
|
||||
* This is function is included in the workbook
|
||||
* because it creates/modifies name records which are stored at the
|
||||
* workbook level.
|
||||
* <p>
|
||||
* <p/>
|
||||
* To set just repeating columns:
|
||||
* <pre>
|
||||
* workbook.setRepeatingRowsAndColumns(0,0,1,-1,-1);
|
||||
@ -863,21 +897,57 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
public void setRepeatingRowsAndColumns(int sheetIndex,
|
||||
int startColumn, int endColumn,
|
||||
int startRow, int endRow) {
|
||||
//TODO
|
||||
// Check arguments
|
||||
if ((startColumn == -1 && endColumn != -1) || startColumn < -1 || endColumn < -1 || startColumn > endColumn)
|
||||
throw new IllegalArgumentException("Invalid column range specification");
|
||||
if ((startRow == -1 && endRow != -1) || startRow < -1 || endRow < -1 || startRow > endRow)
|
||||
throw new IllegalArgumentException("Invalid row range specification");
|
||||
|
||||
XSSFSheet sheet = getSheetAt(sheetIndex);
|
||||
boolean removingRange = startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1;
|
||||
|
||||
XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
|
||||
if (removingRange && name != null) {
|
||||
namedRanges.remove(name);
|
||||
return;
|
||||
}
|
||||
if (name == null) {
|
||||
name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
|
||||
String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
|
||||
name.setReference(reference);
|
||||
namedRanges.add(name);
|
||||
}
|
||||
|
||||
XSSFPrintSetup printSetup = sheet.getPrintSetup();
|
||||
printSetup.setValidSettings(false);
|
||||
}
|
||||
|
||||
private String getReferencePrintArea(String sheetName, int startC, int endC, int startR, int endR) {
|
||||
private static String getReferenceBuiltInRecord(String sheetName, int startC, int endC, int startR, int endR) {
|
||||
//windows excel example for built-in title: 'second sheet'!$E:$F,'second sheet'!$2:$3
|
||||
CellReference colRef = new CellReference(sheetName, 0, startC, true, true);
|
||||
CellReference colRef2 = new CellReference(sheetName, 0, endC, true, true);
|
||||
|
||||
String c = "'" + sheetName + "'!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
|
||||
|
||||
CellReference rowRef = new CellReference(sheetName, startR, 0, true, true);
|
||||
CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
|
||||
|
||||
String r = "";
|
||||
|
||||
if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) {
|
||||
r = ",'" + sheetName + "'!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
|
||||
}
|
||||
return c + r;
|
||||
}
|
||||
|
||||
private static String getReferencePrintArea(String sheetName, int startC, int endC, int startR, int endR) {
|
||||
//windows excel example: Sheet1!$C$3:$E$4
|
||||
CellReference colRef = new CellReference(sheetName, startR, startC, true, true);
|
||||
CellReference colRef2 = new CellReference(sheetName, endR, endC, true, true);
|
||||
|
||||
String c = "'" + sheetName + "'!$" + colRef.getCellRefParts()[2] + "$" + colRef.getCellRefParts()[1] + ":$" + colRef2.getCellRefParts()[2] + "$" + colRef2.getCellRefParts()[1];
|
||||
return c;
|
||||
return "'" + sheetName + "'!$" + colRef.getCellRefParts()[2] + "$" + colRef.getCellRefParts()[1] + ":$" + colRef2.getCellRefParts()[2] + "$" + colRef2.getCellRefParts()[1];
|
||||
}
|
||||
|
||||
//****************** NAME RANGE *************************
|
||||
|
||||
private CTDefinedNames getDefinedNames() {
|
||||
return workbook.getDefinedNames() == null ? workbook.addNewDefinedNames() : workbook.getDefinedNames();
|
||||
}
|
||||
@ -894,20 +964,21 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
|
||||
/**
|
||||
* Generates a NameRecord to represent a built-in region
|
||||
*
|
||||
* @return a new NameRecord
|
||||
*/
|
||||
private XSSFName createBuiltInName(String builtInName, int sheetNumber) {
|
||||
if (sheetNumber < 0 || sheetNumber+1 > Short.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("Sheet number ["+sheetNumber+"]is not valid ");
|
||||
if (sheetNumber < 0 || sheetNumber + 1 > Short.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("Sheet number [" + sheetNumber + "]is not valid ");
|
||||
}
|
||||
|
||||
CTDefinedName nameRecord=getDefinedNames().addNewDefinedName();
|
||||
CTDefinedName nameRecord = getDefinedNames().addNewDefinedName();
|
||||
nameRecord.setName(builtInName);
|
||||
nameRecord.setLocalSheetId(sheetNumber);
|
||||
|
||||
XSSFName name=new XSSFName(nameRecord,this);
|
||||
for(XSSFName nr : namedRanges){
|
||||
if(nr.equals(name))
|
||||
XSSFName name = new XSSFName(nameRecord, this);
|
||||
for (XSSFName nr : namedRanges) {
|
||||
if (nr.equals(name))
|
||||
throw new RuntimeException("Builtin (" + builtInName
|
||||
+ ") already exists for sheet (" + sheetNumber + ")");
|
||||
}
|
||||
@ -915,8 +986,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
||||
return name;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
|
||||
/**
|
||||
* We only set one sheet as selected for compatibility with HSSF.
|
||||
*/
|
||||
|
@ -522,7 +522,7 @@ public class TestXSSFSheet extends TestCase {
|
||||
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.getScenarioProtect());
|
||||
}
|
||||
|
||||
/*
|
||||
public void testTopRowLeftCol() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
||||
@ -533,7 +533,7 @@ public class TestXSSFSheet extends TestCase {
|
||||
assertEquals((short) 2, sheet.getTopRow());
|
||||
assertEquals((short) 26, sheet.getLeftCol());
|
||||
}
|
||||
|
||||
*/
|
||||
public void testShiftRows() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
|
||||
@ -644,8 +644,8 @@ public class TestXSSFSheet extends TestCase {
|
||||
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
|
||||
sheet.createFreezePane(3, 6, 10, 10);
|
||||
assertEquals((double)3, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit());
|
||||
assertEquals(10, sheet.getTopRow());
|
||||
assertEquals(10, sheet.getLeftCol());
|
||||
// assertEquals(10, sheet.getTopRow());
|
||||
// assertEquals(10, sheet.getLeftCol());
|
||||
sheet.createSplitPane(4, 8, 12, 12, 1);
|
||||
assertEquals((double)8, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getYSplit());
|
||||
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
|
||||
@ -844,6 +844,11 @@ public class TestXSSFSheet extends TestCase {
|
||||
}
|
||||
|
||||
|
||||
public void testSetColumnGroupCollapsed(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testColumnWidthCompatibility() {
|
||||
Workbook wb1 = new HSSFWorkbook();
|
||||
Workbook wb2 = new XSSFWorkbook();
|
||||
|
@ -169,7 +169,7 @@ public final class TestXSSFWorkbook extends TestCase {
|
||||
assertEquals("'"+sheetName+"'!$B$5:$F$10", retrievedPrintArea);
|
||||
}
|
||||
|
||||
public void _testRepeatingRowsAndColums() {
|
||||
public void testRepeatingRowsAndColums() {
|
||||
// First test that setting RR&C for same sheet more than once only creates a
|
||||
// single Print_Titles built-in record
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
@ -206,6 +206,10 @@ public final class TestXSSFWorkbook extends TestCase {
|
||||
assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
|
||||
assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getReference());
|
||||
|
||||
|
||||
nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
|
||||
|
||||
|
||||
if (false) {
|
||||
// In case you fancy checking in excel, to ensure it
|
||||
// won't complain about the file now
|
||||
@ -214,13 +218,13 @@ public final class TestXSSFWorkbook extends TestCase {
|
||||
FileOutputStream fout = new FileOutputStream(tempFile);
|
||||
nwb.write(fout);
|
||||
fout.close();
|
||||
System.out.println("check out " + tempFile.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that we can save a new document
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user