本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFSheet.autoSizeColumn方法的具体用法?Java HSSFSheet.autoSizeColumn怎么用?Java HSSFSheet.autoSizeColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.autoSizeColumn方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHeader
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private void createHeader(HSSFSheet sheet, List<ExpedientConsultaDissenyDto> expedientsConsultaDissenyDto) {
int rowNum = 0;
int colNum = 0;
// Capçalera
HSSFRow xlsRow = sheet.createRow(rowNum++);
HSSFCell cell;
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient")));
cell.setCellStyle(headerStyle);
Iterator<Entry<String, DadaIndexadaDto>> it = expedientsConsultaDissenyDto.get(0).getDadesExpedient().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, DadaIndexadaDto> e = (Map.Entry<String, DadaIndexadaDto>)it.next();
sheet.autoSizeColumn(colNum);
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(e.getValue().getEtiqueta())));
cell.setCellStyle(headerStyle);
}
}
示例2: setColumWidth
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private static void setColumWidth(ExcelFileType type,ExportInfo exportInfo,
List<Field> availableFields,Sheet sheet) {
Map<Field, ExportFieldInfo> fieldInfoMap = exportInfo.getFieldInfoMap();
for(int i = 0 ; i < availableFields.size() ; i++){
Field field = availableFields.get(i);
ExportFieldInfo excelFieldInfo = fieldInfoMap.get(field);
if (excelFieldInfo.getWidth() != null) {
sheet.setColumnWidth(i, excelFieldInfo.getWidth()*256);
continue;
}
if(excelFieldInfo.getAutoWidth() != null){
if(ExcelFileType.XLS == type){
HSSFSheet hSheet = (HSSFSheet) sheet;
hSheet.autoSizeColumn(i);
}else if(ExcelFileType.XLSX == type){
XSSFSheet xSheet = (XSSFSheet) sheet;
xSheet.autoSizeColumn(i);
}
}
}
}
示例3: createHeader
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private boolean createHeader(WorkbookGeneratorContext context,
HSSFSheet sheet,
HSSFCellStyle style) {
if (context.headerNames == null || context.headerNames.isEmpty()) {
return false;
}
int headerRowIndex = 0;
HSSFRow rowHeader = sheet.createRow(headerRowIndex);
for (int i = 0; i < context.headerNames.size(); i++) {
HSSFCell cell = rowHeader.createCell(i);
sheet.autoSizeColumn((short) i);
cell.setCellStyle(style);
cell.setCellValue(new HSSFRichTextString(context.headerNames.get(i)));
}
return true;
}
示例4: writeHead
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 写入表头
* @param sheet
*/
void writeHead(HSSFSheet sheet){
LinkedHashMap<String, Object> columnJson = getColumnJson();
Set<String> keySet = columnJson.keySet();
int cellNumber = 0;
HSSFRow row = sheet.createRow(addRowNumber());
for (String k : keySet) {
Object name = columnJson.get(k);//品项编码
sheet.autoSizeColumn(cellNumber);
HSSFCell cell = row.createCell(cellNumber++);
setCellValue(cell, name);
pubMaxValue(k,name);
}
}
示例5: writeSheetHead
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 初始化表头
* @param sheet
* @param columnJson
* @param rowNumber
*/
private static void writeSheetHead(HSSFSheet sheet,JSONObject columnJson,int rowNumber){
if (logger.isDebugEnabled()) {
logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - start"); //$NON-NLS-1$
}
Set<String> keySet = columnJson.keySet();
int cellNumber = 0;
HSSFRow row = sheet.createRow(rowNumber);
for (String k : keySet) {//k:GOODS_NO
String name = columnJson.getString(k);//品项编码
sheet.autoSizeColumn(cellNumber);
HSSFCell cell = row.createCell(cellNumber++);
cell.setCellValue(name);
}
if (logger.isDebugEnabled()) {
logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - end"); //$NON-NLS-1$
}
}
示例6: createHeader
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private void createHeader(
HSSFWorkbook wb,
HSSFSheet sheet,
List<TascaDadaDto> informeCamps) {
HSSFFont bold;
bold = wb.createFont();
bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
bold.setColor(HSSFColor.WHITE.index);
HSSFCellStyle headerStyle;
headerStyle = wb.createCellStyle();
headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
headerStyle.setFillBackgroundColor(HSSFColor.GREY_80_PERCENT.index);
headerStyle.setFont(bold);
int rowNum = 0;
int colNum = 0;
// Capçalera
HSSFRow xlsRow = sheet.createRow(rowNum++);
HSSFCell cell;
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient")));
cell.setCellStyle(headerStyle);
for (TascaDadaDto camp : informeCamps) {
sheet.autoSizeColumn(colNum);
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(camp.getCampEtiqueta())));
cell.setCellStyle(headerStyle);
}
}
示例7: createCell
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private HSSFCellStyle createCell(
WorkbookGeneratorContext context,
HSSFWorkbook workBook,
HSSFSheet sheet,
HSSFCellStyle style,
Object object,
HSSFRow rowData) throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
// 列作成
HSSFCellStyle dateStyle = null;
for (int i = 0; i < context.outputFieldNames.size(); i++) {
HSSFCell cell = rowData.createCell(i);
sheet.autoSizeColumn((short) i);
Object value = PropertyGetUtil.getValue(object, context.outputFieldNames.get(i));
if (value instanceof Date) {
if (dateStyle == null) {
dateStyle = initializeDateCellStyle(workBook, style);
}
setCellValue(cell, value);
cell.setCellStyle(dateStyle);
} else if (isNumber(value)) {
if (value != null) {
cell.setCellValue(Double.valueOf(String.valueOf(value)));
}
setCellValue(cell, value);
setCellStyle(cell, style);
} else {
if (value != null) {
cell.setCellValue(new HSSFRichTextString(String.valueOf(value)));
}
setCellValue(cell, value);
setCellStyle(cell, style);
}
}
return dateStyle;
}
示例8: autoSheetWidth
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 初始化表单的列宽
* @param sheet
* @param columnJson
*/
private static void autoSheetWidth(HSSFSheet sheet,JSONObject columnJson){
if (logger.isDebugEnabled()) {
logger.debug("autoSheetWidth(HSSFSheet, JSONObject) - start"); //$NON-NLS-1$
}
Set<String> keySet = columnJson.keySet();
for (int i = 0;i<keySet.size();i++) {
sheet.autoSizeColumn(i);
}
if (logger.isDebugEnabled()) {
logger.debug("autoSheetWidth(HSSFSheet, JSONObject) - end"); //$NON-NLS-1$
}
}
示例9: storeExcel
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private IStatus storeExcel ( final File file, final List<Event> events, final List<Field> columns, final IProgressMonitor monitor ) throws IOException
{
final HSSFWorkbook workbook = new HSSFWorkbook ();
final HSSFDataFormat dateFormat = workbook.createDataFormat ();
final HSSFCellStyle dateCellStyle = workbook.createCellStyle ();
dateCellStyle.setDataFormat ( dateFormat.getFormat ( "YYYY-MM-DD hh:mm:ss.000" ) );
try
{
monitor.beginTask ( Messages.ExportImpl_Progress_ExportingEvents, events.size () + 3 + columns.size () );
try
{
monitor.subTask ( Messages.ExportImpl_Progress_CreateWorkbook );
monitor.worked ( 1 );
final HSSFSheet sheet = createSheet ( events, workbook, columns );
monitor.worked ( 1 );
monitor.setTaskName ( Messages.ExportImpl_Progress_ExportEvents );
for ( int i = 0; i < events.size (); i++ )
{
final HSSFRow row = sheet.createRow ( i + 1 );
final Event e = events.get ( i );
for ( int j = 0; j < columns.size (); j++ )
{
final Field field = columns.get ( j );
final ExcelCell cell = new ExcelCell ( row, j, dateCellStyle );
field.render ( e, cell );
}
monitor.worked ( 1 );
if ( monitor.isCanceled () )
{
return Status.CANCEL_STATUS;
}
}
sheet.setRepeatingRows ( new CellRangeAddress ( 0, 1, -1, -1 ) );
monitor.setTaskName ( "Auto sizing" );
for ( int i = 0; i < columns.size (); i++ )
{
monitor.subTask ( String.format ( "Auto sizing column: %s", columns.get ( i ).getHeader () ) );
sheet.autoSizeColumn ( i );
monitor.worked ( 1 );
if ( monitor.isCanceled () )
{
return Status.CANCEL_STATUS;
}
}
}
finally
{
monitor.subTask ( Messages.ExportImpl_Progress_CloseFile );
if ( workbook != null )
{
makeDocInfo ( workbook );
final FileOutputStream stream = new FileOutputStream ( file );
workbook.write ( stream );
stream.close ();
}
monitor.worked ( 1 );
}
}
finally
{
monitor.done ();
}
return Status.OK_STATUS;
}
示例10: writeExcel
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 输出excel接口文档
*
* @param param 请求参数 如:a=1&b=&c=
* @param url 接口地址
* @param interfaceName 接口名称
* @param result 请求结果
* @throws Exception
*/
public static void writeExcel(String param, String url, String interfaceName, JsonObject result) throws Exception {
HSSFWorkbook wb = new HSSFWorkbook();
STYLE_MAP.clear();
HSSFSheet sheet = wb.createSheet(interfaceName);
int rowIndex = 0;
setRegionBorder(sheet, rowIndex, 0, 9);//这操作会自动创建row
HSSFRow row = sheet.getRow(rowIndex++);//如果这里再创建row原来合并的单元格式样式将被覆盖
getCell(row, 0, HSSFColor.DARK_YELLOW.index, "业务描述");
setRegionBorder(sheet, rowIndex, 0, 9);
row = sheet.getRow(rowIndex++);
getCell(row, 0, HSSFColor.LIGHT_YELLOW.index, "");
setRegionBorder(sheet, rowIndex, 3, 7);
row = sheet.getRow(rowIndex++);
getCell(row, 0, -1, "创建者");
getCell(row, 2, -1, "创建时间");
getCell(row, 3, -1, DateUtil.formatDate(new Date(), "yyyy-MM-dd"));
getCell(row, 8, -1, "适用");
getCell(row, 9, -1, "教师端");
setRegionBorder(sheet, rowIndex, 1, 7);
row = sheet.getRow(rowIndex++);
getCell(row, 0, -1, "接口名称");
getCell(row, 1, -1, url.substring(url.indexOf("app")));
getCell(row, 8, -1, "协议");
getCell(row, 9, -1, "HTTP(POST)");
setRegionBorder(sheet, rowIndex, 1, 9);
row = sheet.getRow(rowIndex++);
getCell(row, 0, -1, "接口描述");
setRegionBorder(sheet, rowIndex, 2, 7);
row = sheet.getRow(rowIndex++);
getCell(row, 0, -1, "变更历史");
getCell(row, 1, -1, "时间");
getCell(row, 2, -1, "操作内容");
getCell(row, 8, -1, "操作人");
getCell(row, 9, -1, "备注");
rowIndex = createEmptyRow(sheet, rowIndex);
rowIndex = createEmptyRow(sheet, rowIndex);
rowIndex = createEmptyRow(sheet, rowIndex);
rowIndex = setTitle(sheet, rowIndex++, "参数");
if (param != null && !param.trim().isEmpty()) {
String[] pms = param.split("&");
for (String pm : pms) {
setData(sheet, rowIndex++, pm.split("=")[0], "String");
}
}
rowIndex = setTitle(sheet, rowIndex++, "返回值");
LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
analysisJson(map, result, "");
index = rowIndex;
analysisMap(map, sheet);
sheet.autoSizeColumn(0, true);
sheet.autoSizeColumn(1, true);
sheet.autoSizeColumn(9, true);
try (FileOutputStream fileOut = new FileOutputStream(interfaceName + ".xls")) {
wb.write(fileOut);
}
}
示例11: createWorkbook
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
@Override
public Workbook createWorkbook(List<Indicacao> indicacoes) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Indicações");
int rownum = 0;
int colnum = 0;
Cell cell;
Row row;
row = sheet.createRow(rownum++);
cell = row.createCell(colnum++);
cell.setCellValue("Diário");
cell = row.createCell(colnum++);
cell.setCellValue("Número");
cell = row.createCell(colnum++);
cell.setCellValue("Ano");
cell = row.createCell(colnum++);
cell.setCellValue("Data");
cell = row.createCell(colnum++);
cell.setCellValue("Vereador");
cell = row.createCell(colnum++);
cell.setCellValue("Descrição");
cell = row.createCell(colnum++);
cell.setCellValue("Rua");
cell = row.createCell(colnum++);
cell.setCellValue("Obs");
cell = row.createCell(colnum++);
cell.setCellValue("Bairro");
for (Indicacao ind : indicacoes) {
row = sheet.createRow(rownum++);
// FIXME Stop ignoring diary number and extract, maybe from metadata
colnum = 1; // Ignoring diary number
cell = row.createCell(colnum++);
cell.setCellValue(ind.getNumber());
cell = row.createCell(colnum++);
cell.setCellValue(ind.getYear());
colnum++; // Ignoring date column
cell = row.createCell(colnum++);
String vereadores = ind.vereadoresToString();
cell.setCellValue(vereadores);
cell = row.createCell(colnum++);
cell.setCellValue(ind.getDescricao());
cell = row.createCell(colnum++);
cell.setCellValue(ind.ruasToString());
// FIXME Think a way to extract obs
colnum++; // Ignoring "obs" column
cell = row.createCell(colnum++);
cell.setCellValue(ind.getBairro());
}
for (int i = 0; i < colnum; i++)
sheet.autoSizeColumn(i);
return workbook;
}
示例12: createFile
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
public void createFile(List<List<Creature>> listList, File file) {
StringReader reader = new StringReader();
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet1 = workbook.createSheet("Cycle1");
// Heading
HSSFRow heading = sheet1.createRow(0);
for(int j = 0; j < listList.size();j++){
List<Creature> list = new ArrayList<Creature>(listList.get(j));
heading.createCell(0+j*13).setCellValue("DNA");
heading.createCell(1+j*13).setCellValue("LifeExpectancy");
heading.createCell(2+j*13).setCellValue("Height");
heading.createCell(3+j*13).setCellValue("Width");
heading.createCell(4+j*13).setCellValue("Speed");
heading.createCell(5+j*13).setCellValue("Flight");
heading.createCell(6+j*13).setCellValue("OptTemperature");
heading.createCell(7+j*13).setCellValue("NumOffspring");
heading.createCell(8+j*13).setCellValue("PairChance");
heading.createCell(9+j*13).setCellValue("Carnivorous");
heading.createCell(10+j*13).setCellValue("#Environment");
List<String> uniqueDnaSequence = getAllDnaSequences(list);
for (int i = 0; i < uniqueDnaSequence.size(); i++) {
HSSFRow row = sheet1.getRow(i+1);
if(row == null){
row= sheet1.createRow(i+1);
}
int allelLength = properties.getAllelLength();
row.createCell(0+j*13).setCellValue(uniqueDnaSequence.get(i));
row.createCell(1+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 1, allelLength));
row.createCell(2+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 2, allelLength));
row.createCell(3+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 3, allelLength));
row.createCell(4+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 4, allelLength));
row.createCell(5+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 5, allelLength));
row.createCell(6+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 6, allelLength));
row.createCell(7+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 7, allelLength));
row.createCell(8+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 8, allelLength));
row.createCell(9+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 9, allelLength));
row.createCell(10+j*13).setCellValue(j);
}
sheet1.autoSizeColumn(0+j*11);
}
FileOutputStream out = new FileOutputStream(file);
workbook.write(out);
out.close();
workbook.close();
System.out.println("Files outputted to c:/EvolutionOutputs");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
示例13: export
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
public static void export(ITable table) throws ProcessingException {
Object[][] data;
if (table.getSelectedRowCount() >= 2) {
data = table.exportTableRowsAsCSV(table.getSelectedRows(), table.getColumnSet().getVisibleColumns(), true, false, false);
}
else {
data = table.exportTableRowsAsCSV(table.getFilteredRows(), table.getColumnSet().getVisibleColumns(), true, false, false);
}
HSSFWorkbook wb = new HSSFWorkbook();
String filename = IOUtility.getTempFileName(".xls");
String safeName = WorkbookUtil.createSafeSheetName("Export");
HSSFSheet sheet = wb.createSheet(safeName);
short rows = 0;
int cols = 0;
for (Object[] line : data) {
HSSFRow row = sheet.createRow(rows);
cols = 0;
for (Object value : line) {
HSSFCell cell = row.createCell(cols);
cell.getCellStyle().setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
// title
if (rows == 0) {
setBold(wb, cell);
}
setCellValue(wb, cell, value, table.getColumnSet().getVisibleColumn(cols));
cols++;
}
rows++;
}
// fit columns
for (int i = 0; i < cols; i++) {
sheet.autoSizeColumn(i);
}
try {
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
catch (Exception e) {
throw new ProcessingException("POI", e);
}
ClientSessionProvider.currentSession().getDesktop().openUri(filename, OpenUriAction.DOWNLOAD);
ClientSession.get().getDesktop().addNotification(new DesktopNotification(TEXTS.get("ExcelFileCreated")));
}