-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed date representation issue; set version to 2.1.1
- Loading branch information
1 parent
a882d92
commit fed1f6d
Showing
4 changed files
with
34 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
package org.mm.cellfie.ui.view; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Point; | ||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
import org.apache.poi.ss.usermodel.Cell; | ||
import org.apache.poi.ss.usermodel.DataFormatter; | ||
import org.apache.poi.ss.usermodel.DateUtil; | ||
import org.apache.poi.ss.usermodel.Row; | ||
import org.apache.poi.ss.usermodel.Sheet; | ||
import org.mm.ss.SpreadSheetUtil; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.swing.JPanel; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTable; | ||
import javax.swing.*; | ||
import javax.swing.table.AbstractTableModel; | ||
import javax.swing.table.JTableHeader; | ||
import java.awt.*; | ||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import org.apache.poi.ss.usermodel.Cell; | ||
import org.apache.poi.ss.usermodel.Row; | ||
import org.apache.poi.ss.usermodel.Sheet; | ||
import org.mm.ss.SpreadSheetUtil; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* @author Josef Hardi <[email protected]> <br> | ||
|
@@ -42,6 +40,8 @@ public class SheetPanel extends JPanel { | |
private int endColumnIndex = START_INDEX; | ||
private int endRowIndex = END_INDEX; | ||
|
||
private final DataFormatter dataFormatter = new DataFormatter(); | ||
|
||
private Point startMousePt; | ||
private Point endMousePt; | ||
|
||
|
@@ -95,6 +95,11 @@ private void setSelectionRange(int startColumnIndex, int startRowIndex, int endC | |
this.endRowIndex = endRowIndex; | ||
} | ||
|
||
private boolean isDateFormatted(Cell cell) | ||
{ | ||
return DateUtil.isCellDateFormatted(cell); | ||
} | ||
|
||
/** | ||
* Returns the array of the cell selection from this UI panel. The array is composed by | ||
* { startColumnIndex, startRowIndex, endColumnIndex, endRowIndex } | ||
|
@@ -151,13 +156,15 @@ public Object getValueAt(int row, int column) { | |
return ""; | ||
case Cell.CELL_TYPE_STRING : | ||
return cell.getStringCellValue(); | ||
case Cell.CELL_TYPE_NUMERIC : | ||
// Check if the numeric is double or integer | ||
if (isInteger(cell.getNumericCellValue())) { | ||
return (int) cell.getNumericCellValue(); | ||
} else { | ||
return cell.getNumericCellValue(); | ||
} | ||
case Cell.CELL_TYPE_NUMERIC : | ||
// Check if the numeric is an integer or double or a date | ||
if (isDateFormatted(cell)) { | ||
return dataFormatter.formatCellValue(cell); | ||
} else if (isInteger(cell.getNumericCellValue())) { | ||
return Integer.toString((int)cell.getNumericCellValue()); | ||
} else { | ||
return Double.toString(cell.getNumericCellValue()); | ||
} | ||
case Cell.CELL_TYPE_BOOLEAN : | ||
return cell.getBooleanCellValue(); | ||
case Cell.CELL_TYPE_FORMULA : | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters