本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFRow.getHeight方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFRow.getHeight方法的具體用法?Java HSSFRow.getHeight怎麽用?Java HSSFRow.getHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFRow
的用法示例。
在下文中一共展示了HSSFRow.getHeight方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRowHeightInPixels
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private float getRowHeightInPixels(final HSSFSheet sheet, final int i) {
final HSSFRow row = sheet.getRow(i);
float height;
if (row != null) {
height = row.getHeight();
} else {
height = sheet.getDefaultRowHeight();
}
return height / 15F;
}
示例2: getRowHeightInPixels
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private float getRowHeightInPixels(HSSFSheet sheet, int i) {
HSSFRow row = sheet.getRow(i);
float height;
if (row != null) {
height = row.getHeight();
} else {
height = sheet.getDefaultRowHeight();
}
return height / 15F;
}
示例3: xlsToHtml
import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private void xlsToHtml() throws Throwable {
FileOutputStream output = new FileOutputStream(new File(htmlPath));
StringBuffer htmlHeaderSB = new StringBuffer();
htmlHeaderSB.append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' "
+ "xmlns='http://www.w3.org/TR/REC-html40'>");
htmlHeaderSB.append("<head><meta http-equiv=Content-Type content='text/html; charset=utf-8'><meta name=ProgId content=Excel.Sheet>"
+ "</head><body>");
output.write(htmlHeaderSB.toString().getBytes());
HSSFSheet sheet;
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath)); // 獲整個Excel
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
if (workbook.getSheetAt(sheetIndex) != null) {
sheet = workbook.getSheetAt(sheetIndex);// 獲得不為空的這個sheet
if (sheet != null) {
int firstRowNum = sheet.getFirstRowNum(); // 第一行
int lastRowNum = sheet.getLastRowNum(); // 最後一行
// 構造Table
output.write(("<table width=\"100%\" style=\"border:1px solid #000;border-width:1px 0 0 1px;margin:2px 0 2px 0;"
+ "border-collapse:collapse;\">").getBytes());
for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
if (sheet.getRow(rowNum) != null) {// 如果行不為空,
HSSFRow row = sheet.getRow(rowNum);
short firstCellNum = row.getFirstCellNum(); // 該行的第一個單元格
short lastCellNum = row.getLastCellNum(); // 該行的最後一個單元格
int height = (int) (row.getHeight() / 15.625); // 行的高度
output.write(("<tr height=\"" + height + "\" style=\"border:1px solid #000;border-width:0 1px 1px 0;"
+ "margin:2px 0 2px 0;\">").getBytes());
for (short cellNum = firstCellNum; cellNum <= lastCellNum; cellNum++) { // 循環該行的每一個單元格
HSSFCell cell = row.getCell(cellNum);
if (cell != null) {
if (cell.getCellType() != HSSFCell.CELL_TYPE_BLANK) {
StringBuffer tdStyle = new StringBuffer("<td style=\"border:1px solid #000; border-width:0 1px 1px 0;"
+ "margin:2px 0 2px 0; ");
HSSFCellStyle cellStyle = cell.getCellStyle();
HSSFPalette palette = workbook.getCustomPalette(); // 類HSSFPalette用於求顏色的國際標準形式
HSSFColor hColor = palette.getColor(cellStyle.getFillForegroundColor());
HSSFColor hColor2 = palette.getColor(cellStyle.getFont(workbook).getColor());
String bgColor = convertToStardColor(hColor);// 背景顏色
short boldWeight = cellStyle.getFont(workbook).getBoldweight(); // 字體粗細
short fontHeight = (short) (cellStyle.getFont(workbook).getFontHeight() / 2); // 字體大小
String fontColor = convertToStardColor(hColor2); // 字體顏色
if (bgColor != null && !"".equals(bgColor.trim())) {
tdStyle.append(" background-color:");
tdStyle.append(bgColor);
tdStyle.append("; ");
}
if (fontColor != null && !"".equals(fontColor.trim())) {
tdStyle.append(" color:");
tdStyle.append(fontColor);
tdStyle.append("; ");
}
tdStyle.append(" font-weight:");
tdStyle.append(boldWeight);
tdStyle.append("; ");
tdStyle.append(" font-size: ");
tdStyle.append(fontHeight);
tdStyle.append("%;");
output.write((tdStyle + "\"").getBytes());
int width = (int) (sheet.getColumnWidth(cellNum) / 35.7); //
int cellRegionCol = getMergerCellRegionCol(sheet, rowNum, cellNum); // 合並的列(solspan)
int cellRegionRow = getMergerCellRegionRow(sheet, rowNum, cellNum);// 合並的行(rowspan)
String align = convertAlignToHtml(cellStyle.getAlignment()); //
String vAlign = convertVerticalAlignToHtml(cellStyle.getVerticalAlignment());
output.write((" align=\"" + align + "\" valign=\"" + vAlign + "\" width=\"" + width + "\" ").getBytes());
output.write((" colspan=\"" + cellRegionCol + "\" rowspan=\"" + cellRegionRow + "\"").getBytes());
output.write((">" + getCellValue(cell) + "</td>").getBytes());
}
}
}
output.write("</tr>".getBytes());
}
}
output.write(("</table>").getBytes());
}
}
}
output.write(("</body></html>").getBytes());
output.close();
}