当前位置: 首页>>代码示例>>Java>>正文


Java HSSFSheet.getColumnWidth方法代码示例

本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFSheet.getColumnWidth方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFSheet.getColumnWidth方法的具体用法?Java HSSFSheet.getColumnWidth怎么用?Java HSSFSheet.getColumnWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.hssf.usermodel.HSSFSheet的用法示例。


在下文中一共展示了HSSFSheet.getColumnWidth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: xlsToHtml

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的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();
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:82,代码来源:OfficeConverter.java

示例2: getColumnWidthInPixels

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private float getColumnWidthInPixels(final HSSFSheet sheet, final int column) {
    final int cw = sheet.getColumnWidth(column);
    final float px = getPixelWidth(sheet, column);
    return cw / px;
}
 
开发者ID:roundrop,项目名称:ermasterr,代码行数:6,代码来源:PictureSheetGenerator.java

示例3: getPixelWidth

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private float getPixelWidth(final HSSFSheet sheet, final int column) {
    final int def = sheet.getDefaultColumnWidth() * 256;
    final int cw = sheet.getColumnWidth(column);
    return cw != def ? 36.56F : 32F;
}
 
开发者ID:roundrop,项目名称:ermasterr,代码行数:6,代码来源:PictureSheetGenerator.java

示例4: getColumnWidthInPixels

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private float getColumnWidthInPixels(HSSFSheet sheet, int column) {
	int cw = sheet.getColumnWidth(column);
	float px = getPixelWidth(sheet, column);
	return (float) cw / px;
}
 
开发者ID:kozake,项目名称:ermaster-k,代码行数:6,代码来源:PictureSheetGenerator.java

示例5: getPixelWidth

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private float getPixelWidth(HSSFSheet sheet, int column) {
	int def = sheet.getDefaultColumnWidth() * 256;
	int cw = sheet.getColumnWidth(column);
	return cw != def ? 36.56F : 32F;
}
 
开发者ID:kozake,项目名称:ermaster-k,代码行数:6,代码来源:PictureSheetGenerator.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFSheet.getColumnWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。