當前位置: 首頁>>代碼示例>>Java>>正文


Java HSSFSheet.autoSizeColumn方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:23,代碼來源:ExpedientInformeController.java

示例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);
			}
		}
	}
}
 
開發者ID:long47964,項目名稱:excel-utils,代碼行數:22,代碼來源:ExcelExportUtil.java

示例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;
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:19,代碼來源:PoiWorkbookGeneratorStrategy.java

示例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);
	}
}
 
開發者ID:leiyong0326,項目名稱:phone,代碼行數:18,代碼來源:ExcelExportSuper.java

示例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$
}
  }
 
開發者ID:leiyong0326,項目名稱:phone,代碼行數:26,代碼來源:ExcelUtil.java

示例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);
	}
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:29,代碼來源:ExpedientConsultaInformeController.java

示例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;
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:37,代碼來源:PoiWorkbookGeneratorStrategy.java

示例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$
}
  }
 
開發者ID:leiyong0326,項目名稱:phone,代碼行數:20,代碼來源:ExcelUtil.java

示例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;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:78,代碼來源:ExportEventsImpl.java

示例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);
    }
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:72,代碼來源:FileUtil.java

示例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;
}
 
開發者ID:eduardohmg,項目名稱:diario-extractor,代碼行數:75,代碼來源:WorkbookExportImpl.java

示例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());
	}
}
 
開發者ID:Stoephu,項目名稱:Evolution-Speciation,代碼行數:52,代碼來源:DataWrapper.java

示例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")));
}
 
開發者ID:innovad,項目名稱:4mila-1.0,代碼行數:56,代碼來源:ExcelUtility.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。