From commits-return-2758-apmail-poi-commits-archive=poi.apache.org@poi.apache.org Thu Jun 23 10:49:39 2011
Return-Path:
X-Original-To: apmail-poi-commits-archive@minotaur.apache.org
Delivered-To: apmail-poi-commits-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id A013F4158
for ; Thu, 23 Jun 2011 10:49:39 +0000 (UTC)
Received: (qmail 97320 invoked by uid 500); 23 Jun 2011 10:49:39 -0000
Delivered-To: apmail-poi-commits-archive@poi.apache.org
Received: (qmail 97286 invoked by uid 500); 23 Jun 2011 10:49:39 -0000
Mailing-List: contact commits-help@poi.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@poi.apache.org
Delivered-To: mailing list commits@poi.apache.org
Received: (qmail 97279 invoked by uid 99); 23 Jun 2011 10:49:39 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jun 2011 10:49:39 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jun 2011 10:49:34 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id E840223888FD
for ; Thu, 23 Jun 2011 10:49:11 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1138819 - in /poi/trunk/src: documentation/content/xdocs/
documentation/content/xdocs/spreadsheet/ java/org/apache/poi/hssf/model/
java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/
java/org/apache/poi/ss/util/ ooxml/jav...
Date: Thu, 23 Jun 2011 10:49:11 -0000
To: commits@poi.apache.org
From: yegor@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20110623104911.E840223888FD@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: yegor
Date: Thu Jun 23 10:49:11 2011
New Revision: 1138819
URL: http://svn.apache.org/viewvc?rev=1138819&view=rev
Log:
Bug 51415 - Fixed Workbook.createSheet(sheetName) to truncate names longer than 31 characters
Modified:
poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/Workbook.java
poi/trunk/src/java/org/apache/poi/ss/util/WorkbookUtil.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
Modified: poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml?rev=1138819&r1=1138818&r2=1138819&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml Thu Jun 23 10:49:11 2011
@@ -92,14 +92,31 @@
New Sheet
- Workbook wb = new HSSFWorkbook();
- //Workbook wb = new XSSFWorkbook();
+ Workbook wb = new HSSFWorkbook(); // or new XSSFWorkbook();
Sheet sheet1 = wb.createSheet("new sheet");
Sheet sheet2 = wb.createSheet("second sheet");
+
+ // Note that sheet name is Excel must not exceed 31 characters
+ // and must not contain any of the any of the following characters:
+ // 0x0000
+ // 0x0003
+ // colon (:)
+ // backslash (\)
+ // asterisk (*)
+ // question mark (?)
+ // forward slash (/)
+ // opening square bracket ([)
+ // closing square bracket (])
+
+ // You can use org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal)}
+ // for a safe way to create valid names, this utility replaces invalid characters with a space (' ')
+ String safeName = WorkbookUtil.createSafeSheetName("[O'Brien's sales*?]"); // returns " O'Brien's sales "
+ Sheet sheet3 = wb.createSheet(safeName);
+
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
-
+
Creating Cells
@@ -271,15 +288,15 @@
so using Java 1.5 you can simply take advantage
of the built in "foreach" support - see below.
- Sheet sheet = wb.getSheetAt(0);
- for (Iterator<Row> rit = sheet.rowIterator(); rit.hasNext(); ) {
- Row row = rit.next();
- for (Iterator<Cell> cit = row.cellIterator(); cit.hasNext(); ) {
- Cell cell = cit.next();
- // Do something here
- }
- }
-
+ sheet sheet = wb.getsheetat(0);
+ for (iterator<row> rit = sheet.rowiterator(); rit.hasnext(); ) {
+ row row = rit.next();
+ for (iterator<cell> cit = row.celliterator(); cit.hasnext(); ) {
+ cell cell = cit.next();
+ // do something here
+ }
+ }
+
Iterate over rows and cells using Java 1.5 foreach loops
Sometimes, you'd like to just iterate over all the rows in
@@ -293,12 +310,12 @@
the cells, and for Sheet gives the
rowIterator() to iterator over all the rows.
- Sheet sheet = wb.getSheetAt(0);
- for (Row row : sheet) {
- for (Cell cell : row) {
- // Do something here
- }
- }
+ Sheet sheet = wb.getSheetAt(0);
+ for (Row row : sheet) {
+ for (Cell cell : row) {
+ // Do something here
+ }
+ }
@@ -314,37 +331,37 @@
in one sheet, print out the cell's reference
(eg A3), and then the cell's contents.
-// import org.apache.poi.ss.usermodel.*;
+ // import org.apache.poi.ss.usermodel.*;
-Sheet sheet1 = wb.getSheetAt(0);
-for (Row row : sheet1) {
- for (Cell cell : row) {
- CellReference cellRef = new CellReference(row.getRowNum(), cell.getCellNum());
- System.out.print(cellRef.formatAsString());
- System.out.print(" - ");
-
- switch(cell.getCellType()) {
- case Cell.CELL_TYPE_STRING:
- System.out.println(cell.getRichStringCellValue().getString());
- break;
- case Cell.CELL_TYPE_NUMERIC:
- if(DateUtil.isCellDateFormatted(cell)) {
- System.out.println(cell.getDateCellValue());
- } else {
- System.out.println(cell.getNumericCellValue());
+ Sheet sheet1 = wb.getSheetAt(0);
+ for (Row row : sheet1) {
+ for (Cell cell : row) {
+ CellReference cellRef = new CellReference(row.getRowNum(), cell.getCellNum());
+ System.out.print(cellRef.formatAsString());
+ System.out.print(" - ");
+
+ switch (cell.getCellType()) {
+ case Cell.CELL_TYPE_STRING:
+ System.out.println(cell.getRichStringCellValue().getString());
+ break;
+ case Cell.CELL_TYPE_NUMERIC:
+ if (DateUtil.isCellDateFormatted(cell)) {
+ System.out.println(cell.getDateCellValue());
+ } else {
+ System.out.println(cell.getNumericCellValue());
+ }
+ break;
+ case Cell.CELL_TYPE_BOOLEAN:
+ System.out.println(cell.getBooleanCellValue());
+ break;
+ case Cell.CELL_TYPE_FORMULA:
+ System.out.println(cell.getCellFormula());
+ break;
+ default:
+ System.out.println();
+ }
}
- break;
- case Cell.CELL_TYPE_BOOLEAN:
- System.out.println(cell.getBooleanCellValue());
- break;
- case Cell.CELL_TYPE_FORMULA:
- System.out.println(cell.getCellFormula());
- break;
- default:
- System.out.println();
- }
- }
-}
+ }
@@ -353,13 +370,13 @@ for (Row row : sheet1) {
For most text extraction requirements, the standard
ExcelExtractor class should provide all you need.
- InputStream inp = new FileInputStream("workbook.xls");
- HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(inp));
- ExcelExtractor extractor = new ExcelExtractor(wb);
-
- extractor.setFormulasNotResults(true);
- extractor.setIncludeSheetNames(false);
- String text = extractor.getText();
+ InputStream inp = new FileInputStream("workbook.xls");
+ HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(inp));
+ ExcelExtractor extractor = new ExcelExtractor(wb);
+
+ extractor.setFormulasNotResults(true);
+ extractor.setIncludeSheetNames(false);
+ String text = extractor.getText();
For very fancy text extraction, XLS to CSV etc,
take a look at
@@ -458,29 +475,29 @@ Examples:
Wrong:
- for (int i = 0; i < 10000; i++) {
- Row row = sheet.createRow(i);
- Cell cell = row.createCell((short) 0);
-
- CellStyle style = workbook.createCellStyle();
- Font font = workbook.createFont();
- font.setBoldweight(Font.BOLDWEIGHT_BOLD);
- style.setFont(font);
- cell.setCellStyle(style);
- }
-
-
Correct:
-
+ for (int i = 0; i < 10000; i++) {
+ Row row = sheet.createRow(i);
+ Cell cell = row.createCell((short) 0);
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(font);
- for (int i = 0; i < 10000; i++) {
- Row row = sheet.createRow(i);
- Cell cell = row.createCell((short) 0);
- cell.setCellStyle(style);
- }
+ cell.setCellStyle(style);
+ }
+
+
Correct:
+
+
+ CellStyle style = workbook.createCellStyle();
+ Font font = workbook.createFont();
+ font.setBoldweight(Font.BOLDWEIGHT_BOLD);
+ style.setFont(font);
+ for (int i = 0; i < 10000; i++) {
+ Row row = sheet.createRow(i);
+ Cell cell = row.createCell((short) 0);
+ cell.setCellStyle(style);
+ }
@@ -1390,7 +1407,7 @@ Examples:
If your workbook has many formulas then it is a good idea to evaluate them before auto-sizing.
- To calculate column width HSSFSheet.autoSizeColumn uses Java2D classes
+ To calculate column width Sheet.autoSizeColumn uses Java2D classes
that throw exception if graphical environment is not available. In case if graphical environment
is not available, you must tell Java that you are running in headless mode and
set the following system property: java.awt.headless=true .
@@ -1692,7 +1709,6 @@ Examples:
};
sheetCF.addConditionalFormatting(regions, cfRules);
- sheetCF.addConditionalFormatting(regions, cfRules);