org.apache.poi.hssf.record.RowRecord Java Examples
The following examples show how to use
org.apache.poi.hssf.record.RowRecord.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HSSFRow.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Creates an HSSFRow from a low level RowRecord object. Only HSSFSheet should do * this. HSSFSheet uses this when an existing file is read in. * * @param book low-level Workbook object containing the sheet that contains this row * @param sheet low-level Sheet object that contains this Row * @param record the low level api object this row should represent * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int) */ HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record) { this.book = book; this.sheet = sheet; row = record; setRowNum(record.getRowNumber()); // Size the initial cell list such that a read only case won't waste // lots of memory, and a create/read followed by adding new cells can // add a bit without needing a resize cells = new HSSFCell[record.getLastCol()+INITIAL_CAPACITY]; // Don't trust colIx boundaries as read by other apps // set the RowRecord empty for the moment record.setEmpty(); // subsequent calls to createCellFromRecord() will update the colIx boundaries properly }
Example #2
Source File: RecordOrderer.java From lams with GNU General Public License v2.0 | 6 votes |
/** * @return <code>true</code> if the specified record id normally appears in the row blocks section * of the sheet records */ public static boolean isRowBlockRecord(int sid) { switch (sid) { case RowRecord.sid: case BlankRecord.sid: case BoolErrRecord.sid: case FormulaRecord.sid: case LabelRecord.sid: case LabelSSTRecord.sid: case NumberRecord.sid: case RKRecord.sid: case ArrayRecord.sid: case SharedFormulaRecord.sid: case TableRecord.sid: return true; } return false; }
Example #3
Source File: RowBlock.java From dremio-oss with Apache License 2.0 | 6 votes |
static boolean isRowBlockRecord(int sid) { switch (sid) { case RowRecord.sid: case BlankRecord.sid: case BoolErrRecord.sid: case FormulaRecord.sid: case LabelRecord.sid: case LabelSSTRecord.sid: case NumberRecord.sid: case RKRecord.sid: case ArrayRecord.sid: case SharedFormulaRecord.sid: case TableRecord.sid: return true; } return false; }
Example #4
Source File: HSSFSheet.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Used internally to create a high level Row object from a low level row object. * USed when reading an existing file * * @param row low level record to represent as a high level Row and add to sheet * @return HSSFRow high level representation */ private HSSFRow createRowFromRecord(RowRecord row) { HSSFRow hrow = new HSSFRow(_workbook, this, row); addRow(hrow, false); return hrow; }
Example #5
Source File: UserModelEventListener.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings({ "static-access", "unused" }) @Override public void processRecord(org.apache.poi.hssf.record.Record record) { switch (record.getSid()) { case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; //顺序进入新的Workbook if (bof.getType() == bof.TYPE_WORKBOOK) { //logger.debug( "开始解析excel 文档....." ); //顺序进入新的Worksheet,因为Event API不会把Excel文件里的所有数据结构都关联起来, //所以这儿一定要记录现在进入第几个sheet了。 } else if (bof.getType() == bof.TYPE_WORKSHEET) { //读取新的一个Sheet页 //logger.debug( "开始解析sheet页面内容..." ); //System.out.println( "sheetNo="+sheetNo); sheetNo++; currentSheetDataMap=new ArrayList<Map<String,Object>>(); } break; //开始解析Sheet的信息,记录sheet,这儿会把所有的sheet都顺序打印出来,如果有多个sheet的话,可以顺序记入到一个List里 case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; //System.out.println( "sheetName="+bsr.getSheetname()); //logger.debug( "New sheet named: " + bsr.getSheetname()); break; //执行行记录事件 case RowRecord.sid: RowRecord rowrec = (RowRecord) record; //logger.debug( "记录开始, first column at " // + rowrec.getFirstCol() + " last column at " // + rowrec.getLastCol()); break; // SSTRecords store a array of unique strings used in Excel. case SSTRecord.sid: sstrec = (SSTRecord) record; for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) { //logger.debug( "String table value " + k + " = " // + sstrec.getString(k)); } break; //发现数字类型的cell,因为数字和日期都是用这个格式,所以下面一定要判断是不是日期格式,另外默认的数字也会被视为日期格式,所以如果是数字的话,一定要明确指定格式!!!!!!! case NumberRecord.sid: NumberRecord nr = (NumberRecord) record; //HSSFDateUtil.isInternalDateFormat(nr.getXFIndex()) 判断是否为时间列 int column=nr.getColumn(); if(column==5||column==6){ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),getTime(nr.getValue())); }else{ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),(int)nr.getValue()); } break; //发现字符串类型,这儿要取字符串的值的话,跟据其index去字符串表里读取 case LabelSSTRecord.sid: LabelSSTRecord lsr = (LabelSSTRecord)record; addDataAndrChangeRow(lsr.getRow(),lsr.getColumn(), sstrec.getString(lsr.getSSTIndex())); //logger.debug( "文字列:"+sstrec.getString(lsr.getSSTIndex())+", 行:"+lsr.getRow()+", 列:"+lsr.getColumn()); break; case BoolErrRecord.sid: //解析boolean错误信息 BoolErrRecord ber = (BoolErrRecord)record; if(ber.isBoolean()){ addDataAndrChangeRow(ber.getRow(),ber.getColumn(), ber.getBooleanValue()); //logger.debug( "Boolean:"+ber.getBooleanValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } if(ber.isError()){ //logger.debug( "Error:"+ber.getErrorValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } break; //空白记录的信息 case BlankRecord.sid: BlankRecord br = (BlankRecord)record; addDataAndrChangeRow(br.getRow(),br.getColumn(), "" ); //logger.debug( "空。 行:"+br.getRow()+", 列:"+br.getColumn()); break; case FormulaRecord.sid: //数式 FormulaRecord fr = (FormulaRecord)record; addDataAndrChangeRow(fr.getRow(),fr.getColumn(), fr.getValue()); //logger.debug( "数字 。 行:"+fr.getRow()+", 列:"+fr.getColumn()); break; } }
Example #6
Source File: UserModelEventListener.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings({ "static-access", "unused" }) @Override public void processRecord(org.apache.poi.hssf.record.Record record) { switch (record.getSid()) { case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; //顺序进入新的Workbook if (bof.getType() == bof.TYPE_WORKBOOK) { //logger.debug( "开始解析excel 文档....." ); //顺序进入新的Worksheet,因为Event API不会把Excel文件里的所有数据结构都关联起来, //所以这儿一定要记录现在进入第几个sheet了。 } else if (bof.getType() == bof.TYPE_WORKSHEET) { //读取新的一个Sheet页 //logger.debug( "开始解析sheet页面内容..." ); //System.out.println( "sheetNo="+sheetNo); sheetNo++; currentSheetDataMap=new ArrayList<Map<String,Object>>(); } break; //开始解析Sheet的信息,记录sheet,这儿会把所有的sheet都顺序打印出来,如果有多个sheet的话,可以顺序记入到一个List里 case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; //System.out.println( "sheetName="+bsr.getSheetname()); //logger.debug( "New sheet named: " + bsr.getSheetname()); break; //执行行记录事件 case RowRecord.sid: RowRecord rowrec = (RowRecord) record; //logger.debug( "记录开始, first column at " // + rowrec.getFirstCol() + " last column at " // + rowrec.getLastCol()); break; // SSTRecords store a array of unique strings used in Excel. case SSTRecord.sid: sstrec = (SSTRecord) record; for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) { //logger.debug( "String table value " + k + " = " // + sstrec.getString(k)); } break; //发现数字类型的cell,因为数字和日期都是用这个格式,所以下面一定要判断是不是日期格式,另外默认的数字也会被视为日期格式,所以如果是数字的话,一定要明确指定格式!!!!!!! case NumberRecord.sid: NumberRecord nr = (NumberRecord) record; //HSSFDateUtil.isInternalDateFormat(nr.getXFIndex()) 判断是否为时间列 int column=nr.getColumn(); if(column==5||column==6){ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),getTime(nr.getValue())); }else{ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),(int)nr.getValue()); } break; //发现字符串类型,这儿要取字符串的值的话,跟据其index去字符串表里读取 case LabelSSTRecord.sid: LabelSSTRecord lsr = (LabelSSTRecord)record; addDataAndrChangeRow(lsr.getRow(),lsr.getColumn(), sstrec.getString(lsr.getSSTIndex())); //logger.debug( "文字列:"+sstrec.getString(lsr.getSSTIndex())+", 行:"+lsr.getRow()+", 列:"+lsr.getColumn()); break; case BoolErrRecord.sid: //解析boolean错误信息 BoolErrRecord ber = (BoolErrRecord)record; if(ber.isBoolean()){ addDataAndrChangeRow(ber.getRow(),ber.getColumn(), ber.getBooleanValue()); //logger.debug( "Boolean:"+ber.getBooleanValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } if(ber.isError()){ //logger.debug( "Error:"+ber.getErrorValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } break; //空白记录的信息 case BlankRecord.sid: BlankRecord br = (BlankRecord)record; addDataAndrChangeRow(br.getRow(),br.getColumn(), "" ); //logger.debug( "空。 行:"+br.getRow()+", 列:"+br.getColumn()); break; case FormulaRecord.sid: //数式 FormulaRecord fr = (FormulaRecord)record; addDataAndrChangeRow(fr.getRow(),fr.getColumn(), fr.getValue()); //logger.debug( "数字 。 行:"+fr.getRow()+", 列:"+fr.getColumn()); break; } }
Example #7
Source File: UserModelEventListener.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings({ "static-access", "unused" }) @Override public void processRecord(org.apache.poi.hssf.record.Record record) { switch (record.getSid()) { case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; //顺序进入新的Workbook if (bof.getType() == bof.TYPE_WORKBOOK) { //logger.debug( "开始解析excel 文档....." ); //顺序进入新的Worksheet,因为Event API不会把Excel文件里的所有数据结构都关联起来, //所以这儿一定要记录现在进入第几个sheet了。 } else if (bof.getType() == bof.TYPE_WORKSHEET) { //读取新的一个Sheet页 //logger.debug( "开始解析sheet页面内容..." ); //System.out.println( "sheetNo="+sheetNo); sheetNo++; currentSheetDataMap=new ArrayList<Map<String,Object>>(); } break; //开始解析Sheet的信息,记录sheet,这儿会把所有的sheet都顺序打印出来,如果有多个sheet的话,可以顺序记入到一个List里 case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; //System.out.println( "sheetName="+bsr.getSheetname()); //logger.debug( "New sheet named: " + bsr.getSheetname()); break; //执行行记录事件 case RowRecord.sid: RowRecord rowrec = (RowRecord) record; //logger.debug( "记录开始, first column at " // + rowrec.getFirstCol() + " last column at " // + rowrec.getLastCol()); break; // SSTRecords store a array of unique strings used in Excel. case SSTRecord.sid: sstrec = (SSTRecord) record; for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) { //logger.debug( "String table value " + k + " = " // + sstrec.getString(k)); } break; //发现数字类型的cell,因为数字和日期都是用这个格式,所以下面一定要判断是不是日期格式,另外默认的数字也会被视为日期格式,所以如果是数字的话,一定要明确指定格式!!!!!!! case NumberRecord.sid: NumberRecord nr = (NumberRecord) record; //HSSFDateUtil.isInternalDateFormat(nr.getXFIndex()) 判断是否为时间列 int column=nr.getColumn(); if(column==5||column==6){ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),getTime(nr.getValue())); }else{ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),(int)nr.getValue()); } break; //发现字符串类型,这儿要取字符串的值的话,跟据其index去字符串表里读取 case LabelSSTRecord.sid: LabelSSTRecord lsr = (LabelSSTRecord)record; addDataAndrChangeRow(lsr.getRow(),lsr.getColumn(), sstrec.getString(lsr.getSSTIndex())); //logger.debug( "文字列:"+sstrec.getString(lsr.getSSTIndex())+", 行:"+lsr.getRow()+", 列:"+lsr.getColumn()); break; case BoolErrRecord.sid: //解析boolean错误信息 BoolErrRecord ber = (BoolErrRecord)record; if(ber.isBoolean()){ addDataAndrChangeRow(ber.getRow(),ber.getColumn(), ber.getBooleanValue()); //logger.debug( "Boolean:"+ber.getBooleanValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } if(ber.isError()){ //logger.debug( "Error:"+ber.getErrorValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } break; //空白记录的信息 case BlankRecord.sid: BlankRecord br = (BlankRecord)record; addDataAndrChangeRow(br.getRow(),br.getColumn(), "" ); //logger.debug( "空。 行:"+br.getRow()+", 列:"+br.getColumn()); break; case FormulaRecord.sid: //数式 FormulaRecord fr = (FormulaRecord)record; addDataAndrChangeRow(fr.getRow(),fr.getColumn(), fr.getValue()); //logger.debug( "数字 。 行:"+fr.getRow()+", 列:"+fr.getColumn()); break; } }
Example #8
Source File: UserModelEventListener.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings({ "static-access", "unused" }) @Override public void processRecord(org.apache.poi.hssf.record.Record record) { switch (record.getSid()) { case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; //顺序进入新的Workbook if (bof.getType() == bof.TYPE_WORKBOOK) { //logger.debug( "开始解析excel 文档....." ); //顺序进入新的Worksheet,因为Event API不会把Excel文件里的所有数据结构都关联起来, //所以这儿一定要记录现在进入第几个sheet了。 } else if (bof.getType() == bof.TYPE_WORKSHEET) { //读取新的一个Sheet页 //logger.debug( "开始解析sheet页面内容..." ); //System.out.println( "sheetNo="+sheetNo); sheetNo++; currentSheetDataMap=new ArrayList<Map<String,Object>>(); } break; //开始解析Sheet的信息,记录sheet,这儿会把所有的sheet都顺序打印出来,如果有多个sheet的话,可以顺序记入到一个List里 case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; //System.out.println( "sheetName="+bsr.getSheetname()); //logger.debug( "New sheet named: " + bsr.getSheetname()); break; //执行行记录事件 case RowRecord.sid: RowRecord rowrec = (RowRecord) record; //logger.debug( "记录开始, first column at " // + rowrec.getFirstCol() + " last column at " // + rowrec.getLastCol()); break; // SSTRecords store a array of unique strings used in Excel. case SSTRecord.sid: sstrec = (SSTRecord) record; for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) { //logger.debug( "String table value " + k + " = " // + sstrec.getString(k)); } break; //发现数字类型的cell,因为数字和日期都是用这个格式,所以下面一定要判断是不是日期格式,另外默认的数字也会被视为日期格式,所以如果是数字的话,一定要明确指定格式!!!!!!! case NumberRecord.sid: NumberRecord nr = (NumberRecord) record; //HSSFDateUtil.isInternalDateFormat(nr.getXFIndex()) 判断是否为时间列 int column=nr.getColumn(); if(column==5||column==6){ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),getTime(nr.getValue())); }else{ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),(int)nr.getValue()); } break; //发现字符串类型,这儿要取字符串的值的话,跟据其index去字符串表里读取 case LabelSSTRecord.sid: LabelSSTRecord lsr = (LabelSSTRecord)record; addDataAndrChangeRow(lsr.getRow(),lsr.getColumn(), sstrec.getString(lsr.getSSTIndex())); //logger.debug( "文字列:"+sstrec.getString(lsr.getSSTIndex())+", 行:"+lsr.getRow()+", 列:"+lsr.getColumn()); break; case BoolErrRecord.sid: //解析boolean错误信息 BoolErrRecord ber = (BoolErrRecord)record; if(ber.isBoolean()){ addDataAndrChangeRow(ber.getRow(),ber.getColumn(), ber.getBooleanValue()); //logger.debug( "Boolean:"+ber.getBooleanValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } if(ber.isError()){ //logger.debug( "Error:"+ber.getErrorValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } break; //空白记录的信息 case BlankRecord.sid: BlankRecord br = (BlankRecord)record; addDataAndrChangeRow(br.getRow(),br.getColumn(), "" ); //logger.debug( "空。 行:"+br.getRow()+", 列:"+br.getColumn()); break; case FormulaRecord.sid: //数式 FormulaRecord fr = (FormulaRecord)record; addDataAndrChangeRow(fr.getRow(),fr.getColumn(), fr.getValue()); //logger.debug( "数字 。 行:"+fr.getRow()+", 列:"+fr.getColumn()); break; } }
Example #9
Source File: UserModelEventListener.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings({ "static-access", "unused" }) @Override public void processRecord(org.apache.poi.hssf.record.Record record) { switch (record.getSid()) { case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; //顺序进入新的Workbook if (bof.getType() == bof.TYPE_WORKBOOK) { //logger.debug( "开始解析excel 文档....." ); //顺序进入新的Worksheet,因为Event API不会把Excel文件里的所有数据结构都关联起来, //所以这儿一定要记录现在进入第几个sheet了。 } else if (bof.getType() == bof.TYPE_WORKSHEET) { //读取新的一个Sheet页 //logger.debug( "开始解析sheet页面内容..." ); //System.out.println( "sheetNo="+sheetNo); sheetNo++; currentSheetDataMap=new ArrayList<Map<String,Object>>(); } break; //开始解析Sheet的信息,记录sheet,这儿会把所有的sheet都顺序打印出来,如果有多个sheet的话,可以顺序记入到一个List里 case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; //System.out.println( "sheetName="+bsr.getSheetname()); //logger.debug( "New sheet named: " + bsr.getSheetname()); break; //执行行记录事件 case RowRecord.sid: RowRecord rowrec = (RowRecord) record; //logger.debug( "记录开始, first column at " // + rowrec.getFirstCol() + " last column at " // + rowrec.getLastCol()); break; // SSTRecords store a array of unique strings used in Excel. case SSTRecord.sid: sstrec = (SSTRecord) record; for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) { //logger.debug( "String table value " + k + " = " // + sstrec.getString(k)); } break; //发现数字类型的cell,因为数字和日期都是用这个格式,所以下面一定要判断是不是日期格式,另外默认的数字也会被视为日期格式,所以如果是数字的话,一定要明确指定格式!!!!!!! case NumberRecord.sid: NumberRecord nr = (NumberRecord) record; //HSSFDateUtil.isInternalDateFormat(nr.getXFIndex()) 判断是否为时间列 int column=nr.getColumn(); if(column==5||column==6){ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),getTime(nr.getValue())); }else{ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),(int)nr.getValue()); } break; //发现字符串类型,这儿要取字符串的值的话,跟据其index去字符串表里读取 case LabelSSTRecord.sid: LabelSSTRecord lsr = (LabelSSTRecord)record; addDataAndrChangeRow(lsr.getRow(),lsr.getColumn(), sstrec.getString(lsr.getSSTIndex())); //logger.debug( "文字列:"+sstrec.getString(lsr.getSSTIndex())+", 行:"+lsr.getRow()+", 列:"+lsr.getColumn()); break; case BoolErrRecord.sid: //解析boolean错误信息 BoolErrRecord ber = (BoolErrRecord)record; if(ber.isBoolean()){ addDataAndrChangeRow(ber.getRow(),ber.getColumn(), ber.getBooleanValue()); //logger.debug( "Boolean:"+ber.getBooleanValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } if(ber.isError()){ //logger.debug( "Error:"+ber.getErrorValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } break; //空白记录的信息 case BlankRecord.sid: BlankRecord br = (BlankRecord)record; addDataAndrChangeRow(br.getRow(),br.getColumn(), "" ); //logger.debug( "空。 行:"+br.getRow()+", 列:"+br.getColumn()); break; case FormulaRecord.sid: //数式 FormulaRecord fr = (FormulaRecord)record; addDataAndrChangeRow(fr.getRow(),fr.getColumn(), fr.getValue()); //logger.debug( "数字 。 行:"+fr.getRow()+", 列:"+fr.getColumn()); break; } }
Example #10
Source File: UserModelEventListener.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
@Override public void processRecord( Record record ) { switch (record.getSid()) { case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; //顺序进入新的Workbook if (bof.getType() == bof.TYPE_WORKBOOK) { logger.debug( debugger, ">>>>>>>>>>开始解析excel 文档....."); //顺序进入新的Worksheet,因为Event API不会把Excel文件里的所有数据结构都关联起来, //所以这儿一定要记录现在进入第几个sheet了。 } else if (bof.getType() == bof.TYPE_WORKSHEET) { //读取新的一个Sheet页 logger.debug( debugger, ">>>>>>>>>>开始解析sheet页面内容..."); sheetNo++; currentSheetDataMap=new ArrayList<Map<String,Object>>(); } break; //开始解析Sheet的信息,记录sheet,这儿会把所有的sheet都顺序打印出来,如果有多个sheet的话,可以顺序记入到一个List里 case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; logger.debug( debugger, ">>>>>>>>>>New sheet named: " + bsr.getSheetname()); break; //执行行记录事件 case RowRecord.sid: RowRecord rowrec = (RowRecord) record; logger.debug( debugger, ">>>>>>>>>>记录开始, first column at " + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol()); break; // SSTRecords store a array of unique strings used in Excel. case SSTRecord.sid: sstrec = (SSTRecord) record; for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) { logger.debug( debugger, ">>>>>>>>>>String table value " + k + " = " + sstrec.getString(k)); } break; //发现数字类型的cell,因为数字和日期都是用这个格式,所以下面一定要判断是不是日期格式,另外默认的数字也会被视为日期格式,所以如果是数字的话,一定要明确指定格式!!!!!!! case NumberRecord.sid: NumberRecord nr = (NumberRecord) record; //HSSFDateUtil.isInternalDateFormat(nr.getXFIndex()) 判断是否为时间列 int column=nr.getColumn(); if(column==5||column==6){ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),getTime(nr.getValue()), debugger); }else{ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),(int)nr.getValue(), debugger); } break; //发现字符串类型,这儿要取字符串的值的话,跟据其index去字符串表里读取 case LabelSSTRecord.sid: LabelSSTRecord lsr = (LabelSSTRecord)record; addDataAndrChangeRow(lsr.getRow(),lsr.getColumn(), sstrec.getString(lsr.getSSTIndex()), debugger); logger.debug( debugger, ">>>>>>>>>>文字列:"+sstrec.getString(lsr.getSSTIndex())+", 行:"+lsr.getRow()+", 列:"+lsr.getColumn()); break; case BoolErrRecord.sid: //解析boolean错误信息 BoolErrRecord ber = (BoolErrRecord)record; if(ber.isBoolean()){ addDataAndrChangeRow(ber.getRow(),ber.getColumn(), ber.getBooleanValue(), debugger); logger.debug( debugger, ">>>>>>>>>>Boolean:"+ber.getBooleanValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } if(ber.isError()){ logger.debug( debugger, ">>>>>>>>>>Error:"+ber.getErrorValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } break; //空白记录的信息 case BlankRecord.sid: BlankRecord br = (BlankRecord)record; addDataAndrChangeRow(br.getRow(),br.getColumn(), "", debugger); logger.debug( debugger, ">>>>>>>>>>空。 行:"+br.getRow()+", 列:"+br.getColumn()); break; case FormulaRecord.sid: //数式 FormulaRecord fr = (FormulaRecord)record; addDataAndrChangeRow(fr.getRow(),fr.getColumn(), fr.getValue(), debugger); logger.debug( debugger, ">>>>>>>>>>数字 。 行:"+fr.getRow()+", 列:"+fr.getColumn()); break; } }
Example #11
Source File: UserModelEventListener.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
@Override public void processRecord( Record record ) { switch (record.getSid()) { case BOFRecord.sid: BOFRecord bof = (BOFRecord) record; //顺序进入新的Workbook if (bof.getType() == bof.TYPE_WORKBOOK) { logger.debug( debugger, ">>>>>>>>>>开始解析excel 文档....."); //顺序进入新的Worksheet,因为Event API不会把Excel文件里的所有数据结构都关联起来, //所以这儿一定要记录现在进入第几个sheet了。 } else if (bof.getType() == bof.TYPE_WORKSHEET) { //读取新的一个Sheet页 logger.debug( debugger, ">>>>>>>>>>开始解析sheet页面内容..."); sheetNo++; currentSheetDataMap=new ArrayList<Map<String,Object>>(); } break; //开始解析Sheet的信息,记录sheet,这儿会把所有的sheet都顺序打印出来,如果有多个sheet的话,可以顺序记入到一个List里 case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; logger.debug( debugger, ">>>>>>>>>>New sheet named: " + bsr.getSheetname()); break; //执行行记录事件 case RowRecord.sid: RowRecord rowrec = (RowRecord) record; logger.debug( debugger, ">>>>>>>>>>记录开始, first column at " + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol()); break; // SSTRecords store a array of unique strings used in Excel. case SSTRecord.sid: sstrec = (SSTRecord) record; for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) { logger.debug( debugger, ">>>>>>>>>>String table value " + k + " = " + sstrec.getString(k)); } break; //发现数字类型的cell,因为数字和日期都是用这个格式,所以下面一定要判断是不是日期格式,另外默认的数字也会被视为日期格式,所以如果是数字的话,一定要明确指定格式!!!!!!! case NumberRecord.sid: NumberRecord nr = (NumberRecord) record; //HSSFDateUtil.isInternalDateFormat(nr.getXFIndex()) 判断是否为时间列 int column=nr.getColumn(); if(column==5||column==6){ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),getTime(nr.getValue()), debugger); }else{ addDataAndrChangeRow(nr.getRow(),nr.getColumn(),(int)nr.getValue(), debugger); } break; //发现字符串类型,这儿要取字符串的值的话,跟据其index去字符串表里读取 case LabelSSTRecord.sid: LabelSSTRecord lsr = (LabelSSTRecord)record; addDataAndrChangeRow(lsr.getRow(),lsr.getColumn(), sstrec.getString(lsr.getSSTIndex()), debugger); logger.debug( debugger, ">>>>>>>>>>文字列:"+sstrec.getString(lsr.getSSTIndex())+", 行:"+lsr.getRow()+", 列:"+lsr.getColumn()); break; case BoolErrRecord.sid: //解析boolean错误信息 BoolErrRecord ber = (BoolErrRecord)record; if(ber.isBoolean()){ addDataAndrChangeRow(ber.getRow(),ber.getColumn(), ber.getBooleanValue(), debugger); logger.debug( debugger, ">>>>>>>>>>Boolean:"+ber.getBooleanValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } if(ber.isError()){ logger.debug( debugger, ">>>>>>>>>>Error:"+ber.getErrorValue()+", 行:"+ber.getRow()+", 列:"+ber.getColumn()); } break; //空白记录的信息 case BlankRecord.sid: BlankRecord br = (BlankRecord)record; addDataAndrChangeRow(br.getRow(),br.getColumn(), "", debugger); logger.debug( debugger, ">>>>>>>>>>空。 行:"+br.getRow()+", 列:"+br.getColumn()); break; case FormulaRecord.sid: //数式 FormulaRecord fr = (FormulaRecord)record; addDataAndrChangeRow(fr.getRow(),fr.getColumn(), fr.getValue(), debugger); logger.debug( debugger, ">>>>>>>>>>数字 。 行:"+fr.getRow()+", 列:"+fr.getColumn()); break; } }
Example #12
Source File: HSSFSheet.java From lams with GNU General Public License v2.0 | 4 votes |
/** * used internally to set the properties given a Sheet object */ private void setPropertiesFromSheet(InternalSheet sheet) { RowRecord row = sheet.getNextRow(); while (row != null) { createRowFromRecord(row); row = sheet.getNextRow(); } Iterator<CellValueRecordInterface> iter = sheet.getCellValueIterator(); long timestart = System.currentTimeMillis(); if (log.check( POILogger.DEBUG )) { log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ", Long.valueOf(timestart)); } HSSFRow lastrow = null; // Add every cell to its row while (iter.hasNext()) { CellValueRecordInterface cval = iter.next(); long cellstart = System.currentTimeMillis(); HSSFRow hrow = lastrow; if (hrow == null || hrow.getRowNum() != cval.getRow()) { hrow = getRow(cval.getRow()); lastrow = hrow; if (hrow == null) { /* we removed this check, see bug 47245 for the discussion around this // Some tools (like Perl module Spreadsheet::WriteExcel - bug 41187) skip the RowRecords // Excel, OpenOffice.org and GoogleDocs are all OK with this, so POI should be too. if (rowRecordsAlreadyPresent) { // if at least one row record is present, all should be present. throw new RuntimeException("Unexpected missing row when some rows already present"); }*/ // create the row record on the fly now. RowRecord rowRec = new RowRecord(cval.getRow()); sheet.addRow(rowRec); hrow = createRowFromRecord(rowRec); } } if (log.check( POILogger.DEBUG )) { if (cval instanceof Record) { log.log( DEBUG, "record id = " + Integer.toHexString( ( (Record) cval ).getSid() ) ); } else { log.log( DEBUG, "record = " + cval ); } } hrow.createCellFromRecord( cval ); if (log.check( POILogger.DEBUG )) { log.log( DEBUG, "record took ", Long.valueOf( System.currentTimeMillis() - cellstart ) ); } } if (log.check( POILogger.DEBUG )) { log.log(DEBUG, "total sheet cell creation took ", Long.valueOf(System.currentTimeMillis() - timestart)); } }
Example #13
Source File: HSSFRow.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Creates new HSSFRow from scratch. Only HSSFSheet should do this. * * @param book low-level Workbook object containing the sheet that contains this row * @param sheet low-level Sheet object that contains this Row * @param rowNum the row number of this row (0 based) * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int) */ HSSFRow(HSSFWorkbook book, HSSFSheet sheet, int rowNum) { this(book, sheet, new RowRecord(rowNum)); }
Example #14
Source File: HSSFRow.java From lams with GNU General Public License v2.0 | 2 votes |
/** * get the lowlevel RowRecord represented by this object - should only be called * by other parts of the high level API * * @return RowRecord this row represents */ protected RowRecord getRowRecord() { return row; }