Lines 17-25
Link Here
|
17 |
|
17 |
|
18 |
package org.apache.poi.xssf.usermodel; |
18 |
package org.apache.poi.xssf.usermodel; |
19 |
|
19 |
|
|
|
20 |
import java.text.DateFormat; |
21 |
import java.text.SimpleDateFormat; |
20 |
import java.util.Calendar; |
22 |
import java.util.Calendar; |
21 |
import java.util.Date; |
23 |
import java.util.Date; |
22 |
|
24 |
|
|
|
25 |
import org.apache.poi.hssf.record.formula.eval.ErrorEval; |
23 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
26 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
24 |
import org.apache.poi.ss.usermodel.Cell; |
27 |
import org.apache.poi.ss.usermodel.Cell; |
25 |
import org.apache.poi.ss.usermodel.CellStyle; |
28 |
import org.apache.poi.ss.usermodel.CellStyle; |
Lines 73-78
Link Here
|
73 |
protected SharedStringSource getSharedStringSource() { |
76 |
protected SharedStringSource getSharedStringSource() { |
74 |
return this.sharedStringSource; |
77 |
return this.sharedStringSource; |
75 |
} |
78 |
} |
|
|
79 |
|
76 |
protected StylesSource getStylesSource() { |
80 |
protected StylesSource getStylesSource() { |
77 |
return this.stylesSource; |
81 |
return this.stylesSource; |
78 |
} |
82 |
} |
Lines 256-269
Link Here
|
256 |
} |
260 |
} |
257 |
throw new NumberFormatException("You cannot get a string value from a non-string cell"); |
261 |
throw new NumberFormatException("You cannot get a string value from a non-string cell"); |
258 |
} |
262 |
} |
259 |
|
263 |
|
|
|
264 |
/** |
265 |
* Sets this cell as the active cell for the worksheet |
266 |
*/ |
260 |
public void setAsActiveCell() { |
267 |
public void setAsActiveCell() { |
261 |
row.getSheet().setActiveCell(cell.getR()); |
268 |
row.getSheet().setActiveCell(cell.getR()); |
262 |
} |
269 |
} |
263 |
|
270 |
|
|
|
271 |
|
264 |
public void setCellComment(Comment comment) { |
272 |
public void setCellComment(Comment comment) { |
265 |
String cellRef = |
273 |
String cellRef = new CellReference(row.getRowNum(), getCellNum()).formatAsString(); |
266 |
new CellReference(row.getRowNum(), getCellNum()).formatAsString(); |
|
|
267 |
row.getSheet().setCellComment(cellRef, (XSSFComment)comment); |
274 |
row.getSheet().setCellComment(cellRef, (XSSFComment)comment); |
268 |
} |
275 |
} |
269 |
|
276 |
|
Lines 352-357
Link Here
|
352 |
} |
359 |
} |
353 |
} |
360 |
} |
354 |
|
361 |
|
|
|
362 |
/** |
363 |
* set the cells type (numeric, formula or string) |
364 |
* @see #CELL_TYPE_NUMERIC |
365 |
* @see #CELL_TYPE_STRING |
366 |
* @see #CELL_TYPE_FORMULA |
367 |
* @see #CELL_TYPE_BLANK |
368 |
* @see #CELL_TYPE_BOOLEAN |
369 |
* @see #CELL_TYPE_ERROR |
370 |
*/ |
355 |
public void setCellType(int cellType) { |
371 |
public void setCellType(int cellType) { |
356 |
switch (cellType) { |
372 |
switch (cellType) { |
357 |
case CELL_TYPE_BOOLEAN: |
373 |
case CELL_TYPE_BOOLEAN: |
Lines 379-391
Link Here
|
379 |
this.cell.setV(String.valueOf(value)); |
395 |
this.cell.setV(String.valueOf(value)); |
380 |
} |
396 |
} |
381 |
|
397 |
|
|
|
398 |
|
399 |
/** |
400 |
* set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as |
401 |
* a date. |
402 |
* |
403 |
* @param value the date value to set this cell to. For formulas we'll set the |
404 |
* precalculated value, for numerics we'll set its value. For other types we |
405 |
* will change the cell to a numeric cell and set its value. |
406 |
*/ |
382 |
public void setCellValue(Date value) { |
407 |
public void setCellValue(Date value) { |
383 |
setCellValue(HSSFDateUtil.getExcelDate(value, false /*this.book.isUsing1904DateWindowing()*/)); // FIXME |
408 |
boolean date1904 = this.row.getSheet().getWorkbook().getWorkbookPr().getDate1904(); |
|
|
409 |
setCellValue(HSSFDateUtil.getExcelDate(value, date1904)); |
384 |
} |
410 |
} |
385 |
|
411 |
|
|
|
412 |
/** |
413 |
* set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as |
414 |
* a date. |
415 |
* |
416 |
* This will set the cell value based on the Calendar's timezone. As Excel |
417 |
* does not support timezones this means that both 20:00+03:00 and |
418 |
* 20:00-03:00 will be reported as the same value (20:00) even that there |
419 |
* are 6 hours difference between the two times. This difference can be |
420 |
* preserved by using <code>setCellValue(value.getTime())</code> which will |
421 |
* automatically shift the times to the default timezone. |
422 |
* |
423 |
* @param value the date value to set this cell to. For formulas we'll set the |
424 |
* precalculated value, for numerics we'll set its value. For othertypes we |
425 |
* will change the cell to a numeric cell and set its value. |
426 |
*/ |
386 |
public void setCellValue(Calendar value) { |
427 |
public void setCellValue(Calendar value) { |
387 |
// TODO Auto-generated method stub |
428 |
boolean date1904 = this.row.getSheet().getWorkbook().getWorkbookPr().getDate1904(); |
388 |
|
429 |
setCellValue( HSSFDateUtil.getExcelDate(value, date1904 )); |
389 |
} |
430 |
} |
390 |
|
431 |
|
391 |
public void setCellValue(String str) { |
432 |
public void setCellValue(String str) { |
Lines 414-421
Link Here
|
414 |
this.cell.setV(value ? TRUE_AS_STRING : FALSE_AS_STRING); |
455 |
this.cell.setV(value ? TRUE_AS_STRING : FALSE_AS_STRING); |
415 |
} |
456 |
} |
416 |
|
457 |
|
|
|
458 |
/** |
459 |
* Returns a string representation of the cell |
460 |
* |
461 |
* This method returns a simple representation, |
462 |
* anthing more complex should be in user code, with |
463 |
* knowledge of the semantics of the sheet being processed. |
464 |
* |
465 |
* Formula cells return the formula string, |
466 |
* rather than the formula result. |
467 |
* Dates are displayed in dd-MMM-yyyy format |
468 |
* Errors are displayed as #ERR<errIdx> |
469 |
*/ |
417 |
public String toString() { |
470 |
public String toString() { |
418 |
return "[" + this.row.getRowNum() + "," + this.getCellNum() + "] " + this.cell.getV(); |
471 |
// return "[" + this.row.getRowNum() + "," + this.getCellNum() + "] " + this.cell.getV(); |
|
|
472 |
switch (getCellType()) { |
473 |
case CELL_TYPE_BLANK: |
474 |
return ""; |
475 |
case CELL_TYPE_BOOLEAN: |
476 |
return getBooleanCellValue() ? "TRUE" : "FALSE"; |
477 |
case CELL_TYPE_ERROR: |
478 |
return ErrorEval.getText(getErrorCellValue()); |
479 |
case CELL_TYPE_FORMULA: |
480 |
return getCellFormula(); |
481 |
case CELL_TYPE_NUMERIC: |
482 |
//TODO apply the dataformat for this cell |
483 |
if (HSSFDateUtil.isCellDateFormatted(this)) { |
484 |
DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy"); |
485 |
return sdf.format(getDateCellValue()); |
486 |
} else { |
487 |
return getNumericCellValue() + ""; |
488 |
} |
489 |
case CELL_TYPE_STRING: |
490 |
return getRichStringCellValue().toString(); |
491 |
default: |
492 |
return "Unknown Cell Type: " + getCellType(); |
493 |
} |
419 |
} |
494 |
} |
420 |
|
495 |
|
421 |
/** |
496 |
/** |