本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFRow.setHeight方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFRow.setHeight方法的具體用法?Java XSSFRow.setHeight怎麽用?Java XSSFRow.setHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.xssf.usermodel.XSSFRow
的用法示例。
在下文中一共展示了XSSFRow.setHeight方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyRow
import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
/**
* @param srcSheet the sheet to copy.
* @param destSheet the sheet to create.
* @param srcRow the row to copy.
* @param destRow the row to create.
* @param styleMap -
*/
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, XSSFRow srcRow, XSSFRow destRow, Map<Integer, XSSFCellStyle> styleMap) {
// manage a list of merged zone in order to not insert two times a merged zone
Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
destRow.setHeight(srcRow.getHeight());
// pour chaque row
for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
if(j<0){
}else{
XSSFCell oldCell = srcRow.getCell(j); // ancienne cell
XSSFCell newCell = destRow.getCell(j); // new cell
if (oldCell != null) {
if (newCell == null) {
newCell = destRow.createCell(j);
}
// copy chaque cell
copyCell(oldCell, newCell, styleMap);
// copy les informations de fusion entre les cellules
//System.out.println("row num: " + srcRow.getRowNum() + " , col: " + (short)oldCell.getColumnIndex());
CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());
if (mergedRegion != null) {
//System.out.println("Selected merged region: " + mergedRegion.toString());
CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
//System.out.println("New merged region: " + newMergedRegion.toString());
CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
if (isNewMergedRegion(wrapper, mergedRegions)) {
mergedRegions.add(wrapper);
destSheet.addMergedRegion(wrapper.range);
}
}
}
}
}
}
示例2: copyRow
import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
/**
* Copy a row from a sheet to another sheet
*
*
* @param srcSheet the sheet to copy
* @param destSheet the sheet to copy into
* @param parentSheetRow the row inside destSheet where we start to copy
* @param parentSheetColumn the column inside destSheet where we start to copy
* @param srcRow the row to copy
* @param destRow the row to create
* @param styleMap style map
*
*/
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, int parentSheetRow, int parentSheetColumn, XSSFRow srcRow, XSSFRow destRow,
Map<Integer, CellStyle> styleMap) {
// manage a list of merged zone in order to not insert two times a
// merged zone
Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
destRow.setHeight(srcRow.getHeight());
// pour chaque row
for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
XSSFCell oldCell = srcRow.getCell(j); // ancienne cell
if (oldCell != null) {
XSSFCell newCell = destRow.createCell(parentSheetColumn + j);
copyCell(oldCell, newCell, styleMap);
CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());
if (mergedRegion != null) {
CellRangeAddress newMergedRegion = new CellRangeAddress(parentSheetRow + mergedRegion.getFirstRow(),
parentSheetRow + mergedRegion.getLastRow(),
parentSheetColumn + mergedRegion.getFirstColumn(),
parentSheetColumn + mergedRegion.getLastColumn());
CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
if (isNewMergedRegion(wrapper, mergedRegions)) {
mergedRegions.add(wrapper);
destSheet.addMergedRegion(wrapper.range);
}
}
}
}
}
示例3: readWorksheet
import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
private void readWorksheet() {
worksheet = new Worksheet();
worksheets.addWorksheet(worksheet);
worksheet.setName(poiWorksheet.getSheetName());
cells = new Cells();
worksheet.setCells(cells);
int firstRowNum = poiWorksheet.getFirstRowNum();
int lastRowNum = poiWorksheet.getLastRowNum();
// 讀取列寬信息
int maxColumnNum = -1;
for (int i = firstRowNum; i <= lastRowNum; i++) {
XSSFRow row = poiWorksheet.getRow(i);
if (row != null) {
int lastCellNum = row.getLastCellNum();
if (lastCellNum > maxColumnNum) {
maxColumnNum = lastCellNum;
}
}
}
int[] columnWidths = new int[maxColumnNum + 1];
for (int i = 0; i < maxColumnNum; i++) {
columnWidths[i] = poiWorksheet.getColumnWidth(i);
columnWidths[i] = (int) (columnWidths[i]
* XSSFWorkbook.DEFAULT_CHARACTER_WIDTH / 256);
}
cells.setColumnWidths(columnWidths);
// 讀取sheet中的行信息
rowCollection = new RowCollection();
cells.setRowCollection(rowCollection);
for (int i = 0; i < firstRowNum; i++) {
row = new Row();
row.setHeight(poiWorksheet.getDefaultRowHeight());
rowCollection.addRow(row);
}
for (int i = firstRowNum; i <= lastRowNum; i++) {
poiRow = poiWorksheet.getRow(i);
if (poiRow == null) {
row = new Row();
row.setHeight(poiWorksheet.getDefaultRowHeight());
} else {
row = readRow(poiRow, i);
}
rowCollection.addRow(row);
}
// 讀取合並單元格信息
readMergedCells();
}
示例4: copyRow
import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
private XSSFRow copyRow(XSSFWorkbook workbook, XSSFSheet worksheet, int sourceRowNum, int destinationRowNum) {
XSSFRow sourceRow = worksheet.getRow(sourceRowNum);
worksheet.shiftRows(destinationRowNum, worksheet.getLastRowNum(), 1, true, false);
XSSFRow newRow = worksheet.createRow(destinationRowNum);
// Loop through source columns to add to new row
for (int i = 0; i < sourceRow.getLastCellNum(); i++) {
// Grab a copy of the old/new cell
XSSFCell oldCell = sourceRow.getCell(i);
XSSFCell newCell = newRow.createCell(i);
// If the old cell is null jump to next cell
if (oldCell == null) {
newCell = null;
continue;
}
newCell.setCellStyle(oldCell.getCellStyle());
// Set the cell data type
newCell.setCellType(oldCell.getCellType());
}
// If there are are any merged regions in the source row, copy to new row
for (int i = 0; i < worksheet.getNumMergedRegions(); i++) {
CellRangeAddress cellRangeAddress = worksheet.getMergedRegion(i);
if (cellRangeAddress.getFirstRow() == sourceRow.getRowNum()) {
CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(),
(newRow.getRowNum() +
(cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow()
)),
cellRangeAddress.getFirstColumn(),
cellRangeAddress.getLastColumn());
worksheet.addMergedRegion(newCellRangeAddress);
}
}
newRow.setHeight(sourceRow.getHeight());
return newRow;
}
示例5: testModifyCellContents
import org.apache.poi.xssf.usermodel.XSSFRow; //導入方法依賴的package包/類
/**
* [Flow #-2] 액셀 파일 수정 : 엑샐 파일 내 셀의 내용을 변경하고 저장할 수 있음
*/
@Test
public void testModifyCellContents() throws Exception {
try {
String content = "Use \n with word wrap on to create a new line";
short rownum = 2;
int cellnum = 2;
log.debug("testModifyCellContents start....");
StringBuffer sb = new StringBuffer();
sb.append(fileLocation).append("/").append("testModifyCellContents.xlsx");
if (!EgovFileUtil.isExistsFile(sb.toString())) {
XSSFWorkbook wbT = new XSSFWorkbook();
wbT.createSheet();
// 엑셀 파일 생성
excelService.createXSSFWorkbook(wbT, sb.toString());
}
// 엑셀 파일 로드
XSSFWorkbook wb = excelService.loadXSSFWorkbook(sb.toString());
log.debug("testModifyCellContents after loadWorkbook....");
XSSFSheet sheet = wb.getSheetAt(0);
Font f2 = wb.createFont();
CellStyle cs = wb.createCellStyle();
cs = wb.createCellStyle();
cs.setFont( f2 );
//Word Wrap MUST be turned on
cs.setWrapText( true );
XSSFRow row = sheet.createRow( rownum );
row.setHeight( (short) 0x349 );
XSSFCell cellx = row.createCell( cellnum );
cellx.setCellType( SXSSFCell.CELL_TYPE_STRING );
cellx.setCellValue( new XSSFRichTextString(content) );
cellx.setCellStyle( cs );
sheet.setColumnWidth( 20, (int) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) );
//excelService.writeWorkbook(wb);
FileOutputStream outx = new FileOutputStream(sb.toString());
wb.write(outx);
outx.close();
// 엑셀 파일 로드
Workbook wb1 = excelService.loadXSSFWorkbook(sb.toString());
Sheet sheet1 = wb1.getSheetAt(0);
Row row1 = sheet1.getRow(rownum);
Cell cell1 = row1.getCell( cellnum );
// 수정된 셀의 내용 점검
log.debug("cell ###" + cell1.getRichStringCellValue() + "###");
log.debug("cont ###" + content + "###");
assertNotSame("TEST", cell1.getRichStringCellValue().toString());
assertEquals(content, cell1.getRichStringCellValue().toString());
} catch (Exception e) {
log.error(e.toString());
throw new Exception(e);
} finally {
log.debug("testModifyCellContents end....");
}
}