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


Java HSSFSheet.setColumnWidth方法代码示例

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


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

示例1: copySheets

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
 * @param newSheet the sheet to create from the copy.
 * @param sheet the sheet to copy.
 * @param copyStyle true copy the style.
 */
public static void copySheets(HSSFSheet newSheet, HSSFSheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, HSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, HSSFCellStyle>() : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
        HSSFRow srcRow = sheet.getRow(i);
        HSSFRow destRow = newSheet.createRow(i);
        if (srcRow != null) {
            Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
            if (srcRow.getLastCellNum() > maxColumnNum) {
                maxColumnNum = srcRow.getLastCellNum();
            }
        }
    }
    for (int i = 0; i <= maxColumnNum; i++) {
        newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
    }
   //Util.copyPictures(newSheet,sheet) ;
}
 
开发者ID:likelet,项目名称:DAtools,代码行数:24,代码来源:Util.java

示例2: test_001

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
@Test
public void test_001()
{
    HSSFWorkbook v_Workbook = new HSSFWorkbook();
    HSSFSheet    v_Sheet    = v_Workbook.createSheet("测试单元格颜色");
    
    v_Sheet.setColumnWidth(0 ,2560);
    
    for (int v_RowIndex=0; v_RowIndex<4000; v_RowIndex++)
    {
        HSSFRow v_Row = v_Sheet.createRow(v_RowIndex);
        
        for (int v_ColIndex=0; v_ColIndex<1; v_ColIndex++)
        {
            HSSFCell      v_Cell = v_Row.createCell(v_ColIndex);
            HSSFCellStyle v_CellStyle = v_Workbook.createCellStyle();
            
            v_CellStyle.setFillForegroundColor((short)(v_RowIndex + 1));
            v_CellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            
            v_Cell.setCellStyle(v_CellStyle);
            v_Cell.setCellValue("" + (v_RowIndex + 1));
        }
    }
    
    ExcelHelp.save(v_Workbook ,"/Users/hy/Downloads/测试2003版本的单元格颜色");
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.report,代码行数:28,代码来源:JU_Excel2003Color.java

示例3: autoSheetWidth

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
 * 自动重置列宽
 * @param sheet
 * @param columnJson
 */
void autoSheetWidth(HSSFSheet sheet){
	Set<String> keySet = getColumnJson().keySet();
	int i = 0;
	for (String key : keySet) {
		Integer width = columnMaxValue.get(key);
		if (width!=null&&width>0) {
			width+=6;
			width*=256;
			sheet.setColumnWidth(i, width);
		}
		i++;
		
	}
   }
 
开发者ID:leiyong0326,项目名称:phone,代码行数:20,代码来源:ExcelExportSuper.java

示例4: downloadXLS

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
 * 批量付款XLS
 * @param list
 * @param filename
 * @param name
 * @return
 * @throws Exception
 */
public FileTransfer downloadXLS(List<String[]> list,
		String filename) throws Exception {
	
	if (list == null) {
		list = new ArrayList<String[]>();
	}
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	HSSFWorkbook wb = new HSSFWorkbook();
	HSSFSheet sheet = wb.createSheet();
	for (int i = 0; i < list.get(0).length; i++) {
		sheet.setColumnWidth(i, (list.get(0)[i].length())*510);
	}
	HSSFRow rows = null;
	for (int i = 0; i < list.size(); i++) {
		rows = sheet.createRow(i);
		
		String cellDate[] = list.get(i);
		HSSFCell cells = null;
		for (int j = 0; j < cellDate.length; j++) {
			cells = rows.createCell( j );
			// cells.setEncoding((short) j);
			cells.setCellValue(cellDate[j]);
		}
	}
	wb.write(buffer);
	return new FileTransfer(filename, "application/x-xls", buffer
			.toByteArray());
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:37,代码来源:DownloadFile.java

示例5: downloadXLSFileBase

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
public FileTransfer downloadXLSFileBase(List<String[]> list,
	String filename, String name) throws Exception {
if (list == null) {
	list = new ArrayList<String[]>();
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();

HSSFCellStyle cs = wb.createCellStyle();
cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

int columnCount = list.get(0).length;
sheet.setColumnWidth((short) 0, (short) 100);
sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
		(short) columnCount));
for (int i = 1; i <= columnCount; i++) {
	sheet.setColumnWidth((short) i, (short) 4000);
}
// 表名
HSSFRow row1 = sheet.createRow(0);
HSSFCell cell = row1.createCell((short) 0);
// cell.setEncoding((short) 0);
cell.setCellValue(name);
cell.setCellStyle(cs);
row1.setHeight((short) 800);

HSSFRow rows = null;
for (int i = 0; i < list.size(); i++) {
	rows = sheet.createRow(i + 1);
	String cellDate[] = list.get(i);
	HSSFCell cells = null;
	for (int j = 0; j < cellDate.length; j++) {
		cells = rows.createCell((short) (j + 1));
		// cells.setEncoding((short) j);
		cells.setCellValue(cellDate[j]);
		cells.setCellStyle(cs);
	}
	if (i == 0) {
		rows.setHeight((short) 600);// 标题行宽
	}
}
wb.write(buffer);
return new FileTransfer(filename, "application/x-xls", buffer
		.toByteArray());
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:52,代码来源:DownloadFile.java

示例6: downloadXLSFileBase

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private FileTransfer downloadXLSFileBase(List<String[]> list,
		String filename, String name) throws Exception {
	if (list == null) {
		list = new ArrayList<String[]>();
	}
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	HSSFWorkbook wb = new HSSFWorkbook();
	HSSFSheet sheet = wb.createSheet();

	HSSFCellStyle cs = wb.createCellStyle();
	cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
	cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
	cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
	cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
	cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	cs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

	int columnCount = list.get(0).length;
	sheet.setColumnWidth((short) 0, (short) 100);
	sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
			(short) columnCount));
	for (int i = 1; i <= columnCount; i++) {
		sheet.setColumnWidth((short) i, (short) 4000);
	}
	// 表名
	HSSFRow row1 = sheet.createRow(0);
	HSSFCell cell = row1.createCell((short) 0);
	// cell.setEncoding((short) 0);
	cell.setCellValue(name);
	cell.setCellStyle(cs);
	row1.setHeight((short) 800);

	HSSFRow rows = null;
	for (int i = 0; i < list.size(); i++) {
		rows = sheet.createRow(i + 1);
		String cellDate[] = list.get(i);
		HSSFCell cells = null;
		for (int j = 0; j < cellDate.length; j++) {
			cells = rows.createCell((short) (j + 1));
			// cells.setEncoding((short) j);
			cells.setCellValue(cellDate[j]);
			cells.setCellStyle(cs);
		}
		if (i == 0) {
			rows.setHeight((short) 600);// 标题行宽
		}
	}
	wb.write(buffer);
	return new FileTransfer(filename, "application/x-xls", buffer
			.toByteArray());
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:52,代码来源:DownloadFileService.java

示例7: exportMotionExcel

import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
 * 为退款经办下载表
 * 
 * @param outfile
 * @param list
 * @param name
 *            表名
 * @param s为每一格的宽度
 * @throws IOException
 */
public FileTransfer exportMotionExcel(List<String[]> list, String filename,
		String name, String[] s) throws Exception {

	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	HSSFWorkbook wb = new HSSFWorkbook();
	HSSFSheet sheet = wb.createSheet();
	HSSFCellStyle cs = wb.createCellStyle();
	// 设置表头的格式
	HSSFCellStyle cs1 = wb.createCellStyle();
	HSSFFont f1 = wb.createFont();
	f1.setFontHeightInPoints((short) 20);// 字体大小
	cs1.setFont(f1);
	cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);

	// 设置表中的格�?
	cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
	cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
	cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
	cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
	cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	cs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
	cs.setWrapText(true);// 自动换行
	// 将页面设�为横向打印模�?
	HSSFPrintSetup hps = sheet.getPrintSetup();
	hps.setLandscape(true); // 将页面设置为横向打印模式
	hps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);// 为A4纸的大小

	int columnCount = list.get(0).length;
	// 表头那一列的的宽�?
	sheet.setColumnWidth((short) 0, (short) 10000);
	// 合并单元�?
	// sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
	// (short) (columnCount-1)));
	// 根据String[] s来设定每一格的宽度
	for (int i = 0; i < columnCount; i++) {
		sheet.setColumnWidth((short) i, (Short.parseShort(s[i])));
	}
	// 表名
	HSSFRow row1 = sheet.createRow(0);
	HSSFCell cell = row1.createCell(0);
	cell.setCellValue(name);
	cell.setCellStyle(cs1);
	row1.setHeight((short) 800);
	sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0,
			(short) (columnCount - 1)));

	HSSFRow rows = null;
	for (int i = 0; i < list.size(); i++) {
		rows = sheet.createRow(i + 1);
		String cellDate[] = list.get(i);
		HSSFCell cells = null;
		for (int j = 0; j < cellDate.length; j++) {
			cells = rows.createCell((short) (j));
			cells.setCellValue(cellDate[j]);
			cells.setCellStyle(cs);
		}
		if (i == 0) {
			rows.setHeight((short) 600);// 标题行宽�?
		}
	}
	wb.write(buffer);
	return new FileTransfer(filename, "application/x-xls", buffer
			.toByteArray());
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:75,代码来源:DownloadFileService.java


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