Browse Source

Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659525 via svnmerge from

https://svn.apache.org:443/repos/asf/poi/trunk

........
  r659525 | nick | 2008-05-23 13:58:56 +0100 (Fri, 23 May 2008) | 1 line
  
  Extend the support for specifying a policy to HSSF on missing / blank cells when fetching, to be able to specify the policy at the HSSFWorkbook level
........
  Also, port this to XSSF


git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@659533 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_5_BETA2
Nick Burch 16 years ago
parent
commit
6c9ab3d4ef

+ 5
- 3
src/documentation/content/xdocs/changes.xml View File



<!-- Don't forget to update status.xml too! --> <!-- Don't forget to update status.xml too! -->
<release version="3.5.1-alpha1" date="2008-04-??"> <release version="3.5.1-alpha1" date="2008-04-??">
<action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
<action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action> <action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action>
<action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action> <action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action>
<action dev="POI-DEVELOPERS" type="add">Initial support for processing OOXML Excel files (.xlsx), both directly through XSSF, and also through the new common UserModel</action> <action dev="POI-DEVELOPERS" type="add">Initial support for processing OOXML Excel files (.xlsx), both directly through XSSF, and also through the new common UserModel</action>
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action> <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
</release> </release>
<release version="3.1-final" date="2008-06-??"> <release version="3.1-final" date="2008-06-??">
<action dev="POI-DEVELOPERS" type="add">45025 - improved FormulaParser parse error messages</action>
<action dev="POI-DEVELOPERS" type="add">45046 - allowed EXTERNALBOOK(0x01AE) to be optional in the LinkTable</action>
<action dev="POI-DEVELOPERS" type="add">45066 - fixed sheet encoding size mismatch problems</action>
<action dev="POI-DEVELOPERS" type="add">Extend the support for specifying a policy to HSSF on missing / blank cells when fetching, to be able to specify the policy at the HSSFWorkbook level</action>
<action dev="POI-DEVELOPERS" type="fix">45025 - improved FormulaParser parse error messages</action>
<action dev="POI-DEVELOPERS" type="fix">45046 - allowed EXTERNALBOOK(0x01AE) to be optional in the LinkTable</action>
<action dev="POI-DEVELOPERS" type="fix">45066 - fixed sheet encoding size mismatch problems</action>
<action dev="POI-DEVELOPERS" type="add">45003 - Support embeded HDGF visio documents</action> <action dev="POI-DEVELOPERS" type="add">45003 - Support embeded HDGF visio documents</action>
<action dev="POI-DEVELOPERS" type="fix">45001 - Partial fix for HWPF Range.insertBefore() and Range.delete() with unicode characters</action> <action dev="POI-DEVELOPERS" type="fix">45001 - Partial fix for HWPF Range.insertBefore() and Range.delete() with unicode characters</action>
<action dev="POI-DEVELOPERS" type="fix">44977 - Support for AM/PM in excel date formats</action> <action dev="POI-DEVELOPERS" type="fix">44977 - Support for AM/PM in excel date formats</action>

+ 5
- 3
src/documentation/content/xdocs/status.xml View File

<!-- Don't forget to update changes.xml too! --> <!-- Don't forget to update changes.xml too! -->
<changes> <changes>
<release version="3.5.1-alpha1" date="2008-04-??"> <release version="3.5.1-alpha1" date="2008-04-??">
<action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
<action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action> <action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action>
<action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action> <action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action>
<action dev="POI-DEVELOPERS" type="add">Initial support for processing OOXML Excel files (.xlsx), both directly through XSSF, and also through the new common UserModel</action> <action dev="POI-DEVELOPERS" type="add">Initial support for processing OOXML Excel files (.xlsx), both directly through XSSF, and also through the new common UserModel</action>
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action> <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
</release> </release>
<release version="3.1-final" date="2008-06-??"> <release version="3.1-final" date="2008-06-??">
<action dev="POI-DEVELOPERS" type="add">45025 - improved FormulaParser parse error messages</action>
<action dev="POI-DEVELOPERS" type="add">45046 - allowed EXTERNALBOOK(0x01AE) to be optional in the LinkTable</action>
<action dev="POI-DEVELOPERS" type="add">45066 - fixed sheet encoding size mismatch problems</action>
<action dev="POI-DEVELOPERS" type="add">Extend the support for specifying a policy to HSSF on missing / blank cells when fetching, to be able to specify the policy at the HSSFWorkbook level</action>
<action dev="POI-DEVELOPERS" type="fix">45025 - improved FormulaParser parse error messages</action>
<action dev="POI-DEVELOPERS" type="fix">45046 - allowed EXTERNALBOOK(0x01AE) to be optional in the LinkTable</action>
<action dev="POI-DEVELOPERS" type="fix">45066 - fixed sheet encoding size mismatch problems</action>
<action dev="POI-DEVELOPERS" type="add">45003 - Support embeded HDGF visio documents</action> <action dev="POI-DEVELOPERS" type="add">45003 - Support embeded HDGF visio documents</action>
<action dev="POI-DEVELOPERS" type="fix">45001 - Partial fix for HWPF Range.insertBefore() and Range.delete() with unicode characters</action> <action dev="POI-DEVELOPERS" type="fix">45001 - Partial fix for HWPF Range.insertBefore() and Range.delete() with unicode characters</action>
<action dev="POI-DEVELOPERS" type="fix">44977 - Support for AM/PM in excel date formats</action> <action dev="POI-DEVELOPERS" type="fix">44977 - Support for AM/PM in excel date formats</action>

+ 22
- 7
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java View File



/** /**
* Get the hssfcell representing a given column (logical cell) * Get the hssfcell representing a given column (logical cell)
* 0-based. If you ask for a cell that is not defined....
* 0-based. If you ask for a cell that is not defined, then
* you get a null. * you get a null.
* This is the basic call, with no policies applied
*
* @param cellnum 0 based column number
* @return HSSFCell representing that column or null if undefined.
*/
private HSSFCell retrieveCell(int cellnum) {
if(cellnum<0||cellnum>=cells.length) return null;
return cells[cellnum];
}
/**
* Get the hssfcell representing a given column (logical cell)
* 0-based. If you ask for a cell that is not defined then
* you get a null, unless you have set a different
* {@link MissingCellPolicy} on the base workbook.
* Short method signature provided to retain binary * Short method signature provided to retain binary
* compatibility. * compatibility.
* *
int ushortCellNum = cellnum & 0x0000FFFF; // avoid sign extension int ushortCellNum = cellnum & 0x0000FFFF; // avoid sign extension
return getCell(ushortCellNum); return getCell(ushortCellNum);
} }
/** /**
* Get the hssfcell representing a given column (logical cell) * Get the hssfcell representing a given column (logical cell)
* 0-based. If you ask for a cell that is not defined....
* you get a null.
* 0-based. If you ask for a cell that is not defined then
* you get a null, unless you have set a different
* {@link MissingCellPolicy} on the base workbook.
* *
* @param cellnum 0 based column number * @param cellnum 0 based column number
* @return HSSFCell representing that column or null if undefined. * @return HSSFCell representing that column or null if undefined.
*/ */
public HSSFCell getCell(int cellnum) { public HSSFCell getCell(int cellnum) {
if(cellnum<0||cellnum>=cells.length) return null;
return cells[cellnum];
return getCell(cellnum, book.getMissingCellPolicy());
} }
/** /**
* @return representing that column or null if undefined + policy allows. * @return representing that column or null if undefined + policy allows.
*/ */
public HSSFCell getCell(int cellnum, MissingCellPolicy policy) { public HSSFCell getCell(int cellnum, MissingCellPolicy policy) {
HSSFCell cell = getCell(cellnum);
HSSFCell cell = retrieveCell(cellnum);
if(policy == RETURN_NULL_AND_BLANK) { if(policy == RETURN_NULL_AND_BLANK) {
return cell; return cell;
} }
* get the number of the first cell contained in this row. * get the number of the first cell contained in this row.
* @return short representing the first logical cell in the row, or -1 if the row does not contain any cells. * @return short representing the first logical cell in the row, or -1 if the row does not contain any cells.
*/ */

public short getFirstCellNum() public short getFirstCellNum()
{ {
if (getPhysicalNumberOfCells() == 0) if (getPhysicalNumberOfCells() == 0)

+ 29
- 2
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java View File

import org.apache.poi.hssf.record.SSTRecord; import org.apache.poi.hssf.record.SSTRecord;
import org.apache.poi.hssf.record.UnicodeString; import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.record.UnknownRecord; import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.formula.Area3DPtg; import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.MemFuncPtg; import org.apache.poi.hssf.record.formula.MemFuncPtg;
import org.apache.poi.hssf.record.formula.UnionPtg; import org.apache.poi.hssf.record.formula.UnionPtg;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;


* someplace else. * someplace else.
*/ */
private HSSFDataFormat formatter; private HSSFDataFormat formatter;
/**
* The policy to apply in the event of missing or
* blank cells when fetching from a row.
* See {@link MissingCellPolicy}
*/
private MissingCellPolicy missingCellPolicy = HSSFRow.RETURN_NULL_AND_BLANK;




/** Extended windows meta file */ /** Extended windows meta file */
log.log(POILogger.DEBUG, "convertLabelRecords exit"); log.log(POILogger.DEBUG, "convertLabelRecords exit");
} }


/**
* Retrieves the current policy on what to do when
* getting missing or blank cells from a row.
* The default is to return blank and null cells.
* {@link MissingCellPolicy}
*/
public MissingCellPolicy getMissingCellPolicy() {
return missingCellPolicy;
}

/**
* Sets the policy on what to do when
* getting missing or blank cells from a row.
* This will then apply to all calls to
* {@link Row.getCell()}. See
* {@link MissingCellPolicy}
*/
public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
this.missingCellPolicy = missingCellPolicy;
}


/**
/**
* sets the order of appearance for a given sheet. * sets the order of appearance for a given sheet.
* *
* @param sheetname the name of the sheet to reorder * @param sheetname the name of the sheet to reorder

+ 17
- 0
src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java View File



package org.apache.poi.ss.usermodel; package org.apache.poi.ss.usermodel;


import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.SheetReferences; import org.apache.poi.hssf.util.SheetReferences;


int getExternalSheetIndex(int internalSheetIndex); int getExternalSheetIndex(int internalSheetIndex);


CreationHelper getCreationHelper(); CreationHelper getCreationHelper();

/**
* Retrieves the current policy on what to do when
* getting missing or blank cells from a row.
* The default is to return blank and null cells.
* {@link MissingCellPolicy}
*/
MissingCellPolicy getMissingCellPolicy();
/**
* Sets the policy on what to do when
* getting missing or blank cells from a row.
* This will then apply to all calls to
* {@link Row.getCell()}. See
* {@link MissingCellPolicy}
*/
void setMissingCellPolicy(MissingCellPolicy missingCellPolicy);
} }

+ 18
- 1
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java View File

import java.io.OutputStream; import java.io.OutputStream;
import java.util.List; import java.util.List;


import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.ss.util.SheetReferences; import org.apache.poi.ss.util.SheetReferences;


public interface Workbook { public interface Workbook {
*/ */
void removePrintArea(int sheetIndex); void removePrintArea(int sheetIndex);


/**
* Retrieves the current policy on what to do when
* getting missing or blank cells from a row.
* The default is to return blank and null cells.
* {@link MissingCellPolicy}
*/
MissingCellPolicy getMissingCellPolicy();
/**
* Sets the policy on what to do when
* getting missing or blank cells from a row.
* This will then apply to all calls to
* {@link Row.getCell()}. See
* {@link MissingCellPolicy}
*/
void setMissingCellPolicy(MissingCellPolicy missingCellPolicy);

/** creates a new named range and add it to the model /** creates a new named range and add it to the model
* @return named range high level * @return named range high level
*/ */
* classes. * classes.
*/ */
CreationHelper getCreationHelper(); CreationHelper getCreationHelper();
}
}

+ 15
- 2
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java View File

return xcell; return xcell;
} }


public Cell getCell(int cellnum) {
private Cell retrieveCell(int cellnum) {
Iterator<Cell> it = cellIterator(); Iterator<Cell> it = cellIterator();
for ( ; it.hasNext() ; ) { for ( ; it.hasNext() ; ) {
Cell cell = it.next(); Cell cell = it.next();
return null; return null;
} }
/**
* Returns the cell at the given (0 based) index,
* with the {@link MissingCellPolicy} from the
* parent Workbook.
*/
public Cell getCell(int cellnum) {
return getCell(cellnum, sheet.getWorkbook().getMissingCellPolicy());
}
/**
* Returns the cell at the given (0 based) index,
* with the specified {@link MissingCellPolicy}
*/
public Cell getCell(int cellnum, MissingCellPolicy policy) { public Cell getCell(int cellnum, MissingCellPolicy policy) {
Cell cell = getCell(cellnum);
Cell cell = retrieveCell(cellnum);
if(policy == RETURN_NULL_AND_BLANK) { if(policy == RETURN_NULL_AND_BLANK) {
return cell; return cell;
} }

+ 24
- 0
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java View File

import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Palette; import org.apache.poi.ss.usermodel.Palette;
import org.apache.poi.ss.usermodel.PictureData; import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.SharedStringSource; import org.apache.poi.ss.usermodel.SharedStringSource;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.StylesSource; import org.apache.poi.ss.usermodel.StylesSource;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.ss.util.SheetReferences; import org.apache.poi.ss.util.SheetReferences;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
private SharedStringSource sharedStringSource; private SharedStringSource sharedStringSource;
private StylesSource stylesSource; private StylesSource stylesSource;
private MissingCellPolicy missingCellPolicy = Row.RETURN_NULL_AND_BLANK;


private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class); private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class);
this.workbook.getSheets().removeSheet(index); this.workbook.getSheets().removeSheet(index);
} }


/**
* Retrieves the current policy on what to do when
* getting missing or blank cells from a row.
* The default is to return blank and null cells.
* {@link MissingCellPolicy}
*/
public MissingCellPolicy getMissingCellPolicy() {
return missingCellPolicy;
}
/**
* Sets the policy on what to do when
* getting missing or blank cells from a row.
* This will then apply to all calls to
* {@link Row.getCell()}. See
* {@link MissingCellPolicy}
*/
public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
this.missingCellPolicy = missingCellPolicy;
}
public void setBackupFlag(boolean backupValue) { public void setBackupFlag(boolean backupValue) {
// TODO Auto-generated method stub // TODO Auto-generated method stub



+ 14
- 1
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java View File

import junit.framework.TestCase; import junit.framework.TestCase;


import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;


/** /**
* Test HSSFRow is okay. * Test HSSFRow is okay.
row.createCell((short)4, HSSFCell.CELL_TYPE_BLANK); row.createCell((short)4, HSSFCell.CELL_TYPE_BLANK);
row.createCell((short)5).setCellValue(4); row.createCell((short)5).setCellValue(4);
// First up, no policy
// First up, no policy given, uses default
assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0).getCellType()); assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0).getCellType());
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
assertEquals(null, row.getCell(2)); assertEquals(null, row.getCell(2));
assertEquals((short)3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals((short)3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
assertEquals((short)4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals((short)4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
assertEquals((short)5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); assertEquals((short)5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum());
// Now change the cell policy on the workbook, check
// that that is now used if no policy given
book.setMissingCellPolicy(HSSFRow.RETURN_BLANK_AS_NULL);
assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0).getCellType());
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType());
assertEquals(null, row.getCell(2));
assertEquals(null, row.getCell(3));
assertEquals(null, row.getCell(4));
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType());
} }
} }

Loading…
Cancel
Save