本文整理汇总了Java中org.apache.poi.ss.util.CellAddress类的典型用法代码示例。如果您正苦于以下问题:Java CellAddress类的具体用法?Java CellAddress怎么用?Java CellAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CellAddress类属于org.apache.poi.ss.util包,在下文中一共展示了CellAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public void cell(String cellReference, String formattedValue, XSSFComment comment) {
// create empty column, if needed
CellAddress currentCellAddress = new CellAddress(cellReference);
for (int i=this.currentColumn;i<currentCellAddress.getColumn();i++) {
this.spreadSheetCellDAOCurrentRow.add(null);
this.currentColumn++;
}
// add column
SpreadSheetCellDAO currentDAO = null;
if (comment!=null) {
currentDAO = new SpreadSheetCellDAO(formattedValue,comment.getString().getString(), "", cellReference,this.sheetName);
} else {
currentDAO = new SpreadSheetCellDAO(formattedValue,"", "", cellReference,this.sheetName);
}
this.currentColumn++;
this.spreadSheetCellDAOCurrentRow.add(currentDAO);
}
示例2: cell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public void cell(String cellReference, String formattedValue, XSSFComment comment) {
CellAddress cellAddress = new CellAddress(cellReference);
int row = cellAddress.getRow();
if (row + 1 <= options.skip()) {
return;
}
internalCount = row;
int column = cellAddress.getColumn();
setFieldValue(formattedValue, type, column);
}
示例3: cell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public void cell(String cellReference, String formattedValue, XSSFComment xssfComment) {
// gracefully handle missing CellRef here in a similar way as XSSFCell does
if(cellReference == null) {
cellReference = new CellAddress(currentRow, currentCol).formatAsString();
}
int column = new CellReference(cellReference).getCol();
currentCol = column;
// We ignore additional cells here since we only care about the cells
// in the columns array i.e. the defined columns
if (column > MAXIMUM_COL_INDEX) {
LOGGER.warn("Invalid Column index found: " + column);
return;
}
ColumnInfo currentColumnInfo = columns[column];
if (isHeaderRow) {
if (! currentColumnInfo.getName().equalsIgnoreCase(formattedValue.trim())){
throw new ZeroCellException(String.format("Expected Column '%s' but found '%s'", currentColumnInfo.getName(), formattedValue));
}
}
// Prevent from trying to write to a null instance
if (Objects.isNull(cur)) return;
writeColumnField(cur, formattedValue, currentColumnInfo, currentRow);
}
示例4: cell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
public void cell(String cellReference, String formattedValue, XSSFComment comment) {
if (firstCellOfRow) {
firstCellOfRow = false;
} else {
_resultRowTmp.append(ExcelValidator.FIELD_SPLIT);
}
// gracefully handle missing CellRef here in a similar way as
// XSSFCell does
if (cellReference == null) {
cellReference = new CellAddress(currentRow, currentCol).formatAsString();
}
// Did we miss any cells?
int thisCol = (new CellReference(cellReference)).getCol();
int missedCols = thisCol - currentCol - 1;
for (int i = 0; i < missedCols; i++) {
_resultRowTmp.append(ExcelValidator.FIELD_SPLIT);
}
currentCol = thisCol;
// Number or string?
try {
Double.parseDouble(formattedValue);
_resultRowTmp.append(formattedValue);
} catch (NumberFormatException e) {
_resultRowTmp.append(formattedValue);
}
}
示例5: init
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
private void init() {
if (commentsTable != null) {
commentCellRefs = new LinkedList<CellAddress>();
//noinspection deprecation
for (CTComment comment : commentsTable.getCTComments().getCommentList().getCommentArray()) {
commentCellRefs.add(new CellAddress(comment.getRef()));
}
}
}
示例6: cell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public void cell(String cellReference, String formattedValue, XSSFComment comment) {
if (this.isNewRow) {
this.isNewRow = false;
}
// gracefully handle missing CellRef here in a similar way as XSSFCell does
if (cellReference == null) {
cellReference = new CellAddress(this.currentRowInSheet, this.currentColInRow).formatAsString();
}
// 获取cellReference指向的列数,0-based
int thisCol = (new CellReference(cellReference)).getCol();
this.currentColInRow = thisCol;
if (formattedValue == null || formattedValue.isEmpty()) {
return;
}
if (this.currentRowInSheet == 0) {
//标题行
if (this.currentSheetInExcel == 0) {
//若是第0个Sheet则添加标题,0-based
this.titles.add(formattedValue);
}
return;
}
if (this.currentRowInSheet == 1) {
//列名行
if (this.currentSheetInExcel == 0) {
//若是第0个Sheet则添加列名,0-based
this.columns.add(formattedValue);
}
return;
}
//数据行
String key = this.columns.get(this.currentColInRow);
Object value = this.getValue(formattedValue);
this.data.put(key, value);
}
示例7: cell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
public void cell(String cellReference, String formattedValue, XSSFComment comment) {
if (firstCellOfRow) {
firstCellOfRow = false;
} else {
_resultRowTmp.append(ExcelValidator.FIELD_SPLIT);
}
// gracefully handle missing CellRef here in a similar way as
// XSSFCell does
if (cellReference == null) {
cellReference = new CellAddress(currentRow, currentCol).formatAsString();
}
// Did we miss any cells?
int thisCol = (new CellReference(cellReference)).getCol();
int missedCols = thisCol - currentCol - 1;
for (int i = 0; i < missedCols; i++) {
_resultRowTmp.append(ExcelValidator.FIELD_SPLIT);
}
currentCol = thisCol;
// Number or string?
try {
Double.parseDouble(formattedValue);
_resultRowTmp.append(formattedValue);
} catch (NumberFormatException e) {
_resultRowTmp.append(formattedValue);
}
}
示例8: getCurrentCell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public PoiCell getCurrentCell() {
final int currentRow, currentColumn;
CellAddress cellRef = poiSheet.getActiveCell();
if (cellRef != null) {
currentRow = Math.max(getFirstRowNum(), Math.min(getLastRowNum(), cellRef.getRow()));
currentColumn = Math.max(getFirstColNum(), Math.min(getLastColNum(), cellRef.getColumn()));
} else {
currentRow = poiSheet.getTopRow();
currentColumn = poiSheet.getLeftCol();
}
return getCell(currentRow, currentColumn);
}
示例9: outputEmptyCellComment
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
/**
* Output an empty-cell comment.
*/
private void outputEmptyCellComment(CellAddress cellRef) {
XSSFComment comment = commentsTable.findCellComment(cellRef);
output.cell(cellRef.formatAsString(), null, comment);
}
示例10: asTable
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Documentation(
value = "Insert a table from an Excel .xlsx file.",
params = {
@Param(name = "uri", value = "The Excel .xlsx file uri, it can be relative to the template"),
@Param(name = "sheetName", value = "The sheet name"),
@Param(name = "topLeftCellAdress", value = "The top left cell address"),
@Param(name = "bottomRightCellAdress", value = "The bottom right cell address"),
@Param(name = "languageTag", value = "The language tag for the locale"),
},
result = "insert the table",
examples = {
@Example(expression = "'excel.xlsx'.asTable('Feuil1', 'C3', 'F7', 'fr-FR')", result = "insert the table from 'excel.xlsx'"),
}
)
// @formatter:on
public MTable asTable(String uriStr, String sheetName, String topLeftCellAdress, String bottomRightCellAdress,
String languageTag) throws IOException {
final MTable res = new MTableImpl();
final URI xlsxURI = URI.createURI(uriStr, false);
final URI uri = xlsxURI.resolve(templateURI);
try (XSSFWorkbook workbook = new XSSFWorkbook(uriConverter.createInputStream(uri));) {
final FormulaEvaluator evaluator = new XSSFFormulaEvaluator(workbook);
final XSSFSheet sheet = workbook.getSheet(sheetName);
if (sheet == null) {
throw new IllegalArgumentException(String.format("The sheet %s doesn't exists in %s.", sheetName, uri));
} else {
final Locale locale;
if (languageTag != null) {
locale = Locale.forLanguageTag(languageTag);
} else {
locale = Locale.getDefault();
}
final DataFormatter dataFormatter = new DataFormatter(locale);
final CellAddress start = new CellAddress(topLeftCellAdress);
final CellAddress end = new CellAddress(bottomRightCellAdress);
int rowIndex = start.getRow();
while (rowIndex <= end.getRow()) {
final XSSFRow row = sheet.getRow(rowIndex++);
if (row != null) {
final MRow mRow = new MRowImpl();
int cellIndex = start.getColumn();
while (cellIndex <= end.getColumn()) {
final XSSFCell cell = row.getCell(cellIndex++);
if (cell != null) {
final MStyle style = getStyle(cell);
final MElement text = new MTextImpl(dataFormatter.formatCellValue(cell, evaluator),
style);
final Color background = getColor(cell.getCellStyle().getFillForegroundColorColor());
final MCell mCell = new MCellImpl(text, background);
mRow.getCells().add(mCell);
} else {
mRow.getCells().add(createEmptyCell());
}
}
res.getRows().add(mRow);
} else {
final int length = end.getColumn() - start.getColumn() + 1;
res.getRows().add(createEmptyRow(length));
}
}
}
}
return res;
}
示例11: write
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
/**
* Add a cell to the current Workbook
*
* @param newDAO cell to add. If it is already existing an exception will be thrown. Note that the sheet name is sanitized using org.apache.poi.ss.util.WorkbookUtil.createSafeSheetName. The Cell address needs to be in A1 format. Either formula or formattedValue must be not null.
*
*/
@Override
public void write(Object newDAO) throws OfficeWriterException {
SpreadSheetCellDAO sscd = checkSpreadSheetCellDAO(newDAO);
String safeSheetName=WorkbookUtil.createSafeSheetName(sscd.getSheetName());
Sheet currentSheet=this.currentWorkbook.getSheet(safeSheetName);
if (currentSheet==null) {// create sheet if it does not exist yet
currentSheet=this.currentWorkbook.createSheet(safeSheetName);
if (!(safeSheetName.equals(sscd.getSheetName()))) {
LOG.warn("Sheetname modified from \""+sscd.getSheetName()+"\" to \""+safeSheetName+"\" to correspond to Excel conventions.");
}
// create drawing anchor (needed for comments...)
this.mappedDrawings.put(safeSheetName,currentSheet.createDrawingPatriarch());
}
// check if cell exist
CellAddress currentCA = new CellAddress(sscd.getAddress());
Row currentRow = currentSheet.getRow(currentCA.getRow());
if (currentRow==null) { // row does not exist? => create it
currentRow=currentSheet.createRow(currentCA.getRow());
}
Cell currentCell = currentRow.getCell(currentCA.getColumn());
if ((currentCell!=null) && (this.hasTemplate==false)) { // cell already exists and no template loaded ? => throw exception
throw new OfficeWriterException("Invalid cell specification: cell already exists at "+currentCA);
}
// create cell if no template is loaded or cell not available in template
if ((this.hasTemplate==false) || (currentCell==null)) {
currentCell=currentRow.createCell(currentCA.getColumn());
}
// set the values accordingly
if (!("".equals(sscd.getFormula()))) { // if formula exists then use formula
currentCell.setCellFormula(sscd.getFormula());
} else {
// else use formattedValue
currentCell.setCellValue(sscd.getFormattedValue());
}
// set comment
if ((sscd.getComment()!=null) && (!("".equals(sscd.getComment())))) {
/** the following operations are necessary to create comments **/
/** Define size of the comment window **/
ClientAnchor anchor = this.currentWorkbook.getCreationHelper().createClientAnchor();
anchor.setCol1(currentCell.getColumnIndex());
anchor.setCol2(currentCell.getColumnIndex()+this.howc.getCommentWidth());
anchor.setRow1(currentRow.getRowNum());
anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
/** create comment **/
Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
currentComment.setAuthor(this.howc.getCommentAuthor());
currentCell.setCellComment(currentComment);
}
}
示例12: write
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public void write(Object newDAO) throws OfficeWriterException {
SpreadSheetCellDAO sscd = MSExcelWriter.checkSpreadSheetCellDAO(newDAO);
String safeSheetName=WorkbookUtil.createSafeSheetName(sscd.getSheetName());
SXSSFSheet currentSheet=this.currentWorkbook.getSheet(safeSheetName);
if (currentSheet==null) {// create sheet if it does not exist yet
currentSheet=this.currentWorkbook.createSheet(safeSheetName);
if (!(safeSheetName.equals(sscd.getSheetName()))) {
LOG.warn("Sheetname modified from \""+sscd.getSheetName()+"\" to \""+safeSheetName+"\" to correspond to Excel conventions.");
}
// create drawing anchor (needed for comments...)
this.mappedDrawings.put(safeSheetName,currentSheet.createDrawingPatriarch());
}
// check if cell exist
CellAddress currentCA = new CellAddress(sscd.getAddress());
SXSSFRow currentRow = currentSheet.getRow(currentCA.getRow());
if (currentRow==null) { // row does not exist? => create it
currentRow=currentSheet.createRow(currentCA.getRow());
}
SXSSFCell currentCell = currentRow.getCell(currentCA.getColumn());
if ((currentCell!=null)) { // cell already exists and no template loaded ? => throw exception
throw new OfficeWriterException("Invalid cell specification: cell already exists at "+currentCA);
}
// create cell if no template is loaded or cell not available in template
currentCell=currentRow.createCell(currentCA.getColumn());
// set the values accordingly
if (!("".equals(sscd.getFormula()))) { // if formula exists then use formula
currentCell.setCellFormula(sscd.getFormula());
} else {
// else use formattedValue
currentCell.setCellValue(sscd.getFormattedValue());
}
// set comment
if ((sscd.getComment()!=null) && (!("".equals(sscd.getComment())))) {
/** the following operations are necessary to create comments **/
/** Define size of the comment window **/
ClientAnchor anchor = this.currentWorkbook.getCreationHelper().createClientAnchor();
anchor.setCol1(currentCell.getColumnIndex());
anchor.setCol2(currentCell.getColumnIndex()+this.howc.getCommentWidth());
anchor.setRow1(currentRow.getRowNum());
anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
/** create comment **/
Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
currentComment.setAuthor(this.howc.getCommentAuthor());
currentCell.setCellComment(currentComment);
}
}
示例13: getActiveCell
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public CellAddress getActiveCell() {
throw new UnsupportedOperationException();
}
示例14: getCellComment
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public Comment getCellComment(CellAddress ref) {
throw new UnsupportedOperationException();
}
示例15: getCellComments
import org.apache.poi.ss.util.CellAddress; //导入依赖的package包/类
@Override
public Map<CellAddress, ? extends Comment> getCellComments() {
throw new UnsupportedOperationException();
}