Java 类org.apache.poi.hssf.usermodel.HSSFPrintSetup 实例源码

项目:ureport    文件:Excel97Producer.java   
private Sheet createSheet(HSSFWorkbook wb,Paper paper,String name){
    Sheet sheet = null;
    if(name==null){
        sheet=wb.createSheet();
    }else{          
        sheet=wb.createSheet(name);
    }
    PaperType paperType=paper.getPaperType();
    HSSFPrintSetup printSetup=(HSSFPrintSetup)sheet.getPrintSetup();
    Orientation orientation=paper.getOrientation();
    if(orientation.equals(Orientation.landscape)){
        printSetup.setLandscape(true);
    }
    setupPaper(paperType, printSetup);
    int leftMargin=paper.getLeftMargin();
    int rightMargin=paper.getRightMargin();
    int topMargin=paper.getTopMargin();
    int bottomMargin=paper.getBottomMargin();
    sheet.setMargin(Sheet.LeftMargin, UnitUtils.pointToInche(leftMargin));
    sheet.setMargin(Sheet.RightMargin, UnitUtils.pointToInche(rightMargin));
    sheet.setMargin(Sheet.TopMargin, UnitUtils.pointToInche(topMargin));
    sheet.setMargin(Sheet.BottomMargin, UnitUtils.pointToInche(bottomMargin));
    return sheet;
}
项目:jasperreports    文件:JRXlsMetadataExporter.java   
private void updateHeaderFooterMargin(Integer marginValue, boolean isHeaderMargin)
{
    if(marginValue != null)
    {
        HSSFPrintSetup printSetup = sheet.getPrintSetup();
        double margin = LengthUtil.inch(marginValue);
        if(isHeaderMargin)
        {
            if(margin > printSetup.getHeaderMargin())
            {
                printSetup.setHeaderMargin(margin);
            }
        }
        else
        {
            if(margin > printSetup.getFooterMargin())
            {
                printSetup.setFooterMargin(margin);
            }
        }
    }
}
项目:SporttagePlaner    文件:KontrollistenWriter.java   
private void close() throws IOException, SQLException {
    // Spaltenbreiten anpassen
    for (int spalte = 0; spalte < 1 + hoechstesBespieltesFeld * 8; spalte++) {
        sheet1.autoSizeColumn(spalte);
    }
    sheet1.getPrintSetup().setPaperSize(HSSFPrintSetup.A4_ROTATED_PAPERSIZE); // A4 Querformat
    wb.setPrintArea(  // Druckbereich setzen
            0, // sheet index
            0, // start column
            hoechstesBespieltesFeld * 8, // end column
            0, // start row
            currentRow - 1 // end row
            );
    wb.write(fos); // Excel-Datei schreiben
    fos.flush();
    fos.close(); // FileOutputStream schließen
    con.close(); // Datenbankverbindung schließen
}
项目:neoscada    文件:ExportEventsImpl.java   
private HSSFSheet createSheet ( final List<Event> events, final HSSFWorkbook workbook, final List<Field> columns )
{
    final HSSFSheet sheet = workbook.createSheet ( Messages.ExportImpl_ExcelSheet_Name );

    final HSSFHeader header = sheet.getHeader ();
    header.setLeft ( Messages.ExportImpl_ExcelSheet_Header );
    header.setRight ( HeaderFooter.date () + " " + HeaderFooter.time () );//$NON-NLS-1$

    final HSSFFooter footer = sheet.getFooter ();
    footer.setLeft ( String.format ( Messages.ExportImpl_ExcelSheet_Footer_1, events.size () ) );

    footer.setRight ( Messages.ExportImpl_ExcelSheet_Footer_2 + HeaderFooter.page () + Messages.ExportImpl_ExcelSheet_Footer_3 + HeaderFooter.numPages () );

    makeHeader ( columns, sheet );

    final HSSFPrintSetup printSetup = sheet.getPrintSetup ();
    printSetup.setLandscape ( true );
    printSetup.setFitWidth ( (short)1 );
    printSetup.setFitHeight ( (short)0 );
    printSetup.setPaperSize ( PrintSetup.A4_PAPERSIZE );

    sheet.setAutoFilter ( new CellRangeAddress ( 0, 0, 0, columns.size () - 1 ) );
    sheet.createFreezePane ( 0, 1 );
    sheet.setFitToPage ( true );
    sheet.setAutobreaks ( true );

    printSetup.setFooterMargin ( 0.25 );

    sheet.setMargin ( Sheet.LeftMargin, 0.25 );
    sheet.setMargin ( Sheet.RightMargin, 0.25 );
    sheet.setMargin ( Sheet.TopMargin, 0.25 );
    sheet.setMargin ( Sheet.BottomMargin, 0.5 );

    return sheet;
}
项目:jasperreports    文件:JRXlsExporter.java   
@Override
protected void closeSheet()
{
    if (sheet == null)
    {
        return;
    }

    HSSFPrintSetup printSetup = sheet.getPrintSetup();

    if (isValidScale(sheetInfo.sheetPageScale))
    {
        printSetup.setScale((short)sheetInfo.sheetPageScale.intValue());
    }
    else
    {
        XlsReportConfiguration configuration = getCurrentItemConfiguration();

        Integer fitWidth = configuration.getFitWidth();
        if (fitWidth != null)
        {
            printSetup.setFitWidth(fitWidth.shortValue());
            sheet.setAutobreaks(true);
        }

        Integer fitHeight = configuration.getFitHeight();
        fitHeight = 
            fitHeight == null
            ? (Boolean.TRUE == configuration.isAutoFitPageHeight() 
                ? (pageIndex - sheetInfo.sheetFirstPageIndex)
                : null)
            : fitHeight;
        if (fitHeight != null)
        {
            printSetup.setFitHeight(fitHeight.shortValue());
            sheet.setAutobreaks(true);
        }
    }
}
项目:jasperreports    文件:JRXlsMetadataExporter.java   
@Override
protected void closeSheet() 
{
    if (sheet == null)
    {
        return;
    }

    HSSFPrintSetup printSetup = sheet.getPrintSetup();

    if (isValidScale(sheetInfo.sheetPageScale))
    {
        printSetup.setScale((short)sheetInfo.sheetPageScale.intValue());
    }
    else
    {
        XlsReportConfiguration configuration = getCurrentItemConfiguration();

        Integer fitWidth = configuration.getFitWidth();
        if (fitWidth != null) 
        {
            printSetup.setFitWidth(fitWidth.shortValue());
            sheet.setAutobreaks(true);
        }

        Integer fitHeight = configuration.getFitHeight();
        fitHeight = 
            fitHeight == null
            ? (Boolean.TRUE == configuration.isAutoFitPageHeight() 
                ? (pageIndex - sheetInfo.sheetFirstPageIndex)
                : null)
            : fitHeight;
        if (fitHeight != null)
        {
            printSetup.setFitHeight(fitHeight.shortValue());
            sheet.setAutobreaks(true);
        }
    }
}
项目:metasfresh    文件:AbstractExcelExporter.java   
protected void formatPage(final HSSFSheet sheet)
{
    sheet.setFitToPage(true);
    // Print Setup
    HSSFPrintSetup ps = sheet.getPrintSetup();
    ps.setFitWidth((short)1);
    ps.setNoColor(true);
    ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);
    ps.setLandscape(false);
}
项目:SporttagePlaner    文件:SpielplanWriter.java   
/**
 * Schließt alle durch den SpielplanWriter geöffneten Ressourcen und schreibt die Excel-Datei
 * 
 * @throws IOException
 * @throws SQLException
 */
private void close() throws IOException, SQLException {
    // Spaltenbreiten anpassen
    hoechstesBespieltesFeld = (hoechstesBespieltesFeld > hoechstesBespieltesFeldMo) ? hoechstesBespieltesFeld : hoechstesBespieltesFeldMo; 
    for (int spalte = 0; spalte < 1 + hoechstesBespieltesFeld * 3; spalte++) {
        sheet1.autoSizeColumn(spalte);
    }
    sheet1.getPrintSetup().setPaperSize(HSSFPrintSetup.A4_ROTATED_PAPERSIZE); // A4 Querformat
    wb.write(fos); // Excel-Datei schreiben
    fos.flush();
    fos.close(); // FileOutputStream schließen
    con.close(); // Datenbankverbindung schließen
}
项目:SporttagePlaner    文件:PfeiflistenMaker.java   
public void close() throws SQLException, IOException {
    con.close();
    for(int i = 0; i < 3; i++) { // Spaltenbreiten anpassen
        sheet1.autoSizeColumn(i);
    }
    sheet1.getPrintSetup().setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);
    wb.write(fos);
    fos.flush();
    fos.close();
}
项目:birt    文件:PageLayoutTest.java   
@Test
public void testRunReportXls() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xls");
    assertNotNull(inputStream);
    try {

        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals( 1, workbook.getNumberOfSheets() );
        assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());

        HSSFSheet sheet0 = workbook.getSheetAt(0);
        HSSFPrintSetup printSetup = sheet0.getPrintSetup();
        assertEquals( HSSFPrintSetup.A4_PAPERSIZE,  printSetup.getPaperSize() );
        assertEquals( true, printSetup.getLandscape() );
        assertEquals( 1.0 / 2.54, printSetup.getHeaderMargin(), 0.01 );
        assertEquals( 1.0 / 2.54, printSetup.getFooterMargin(), 0.01 );
        assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
        assertEquals( 0.7 / 2.54, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
        assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
        assertEquals( 1.7 / 2.54, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );

    } finally {
        inputStream.close();
    }
}
项目:birt    文件:PageLayoutTest.java   
@Test
public void testRunReportPixelsXls() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("PageLayoutPixels.rptdesign", "xls");
    assertNotNull(inputStream);
    try {

        HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals( 1, workbook.getNumberOfSheets() );
        assertEquals( "Page Layout Test", workbook.getSheetAt(0).getSheetName());

        HSSFSheet sheet0 = workbook.getSheetAt(0);
        HSSFPrintSetup printSetup = sheet0.getPrintSetup();
        assertEquals( HSSFPrintSetup.A4_PAPERSIZE,  printSetup.getPaperSize() );
        assertEquals( true, printSetup.getLandscape() );
        assertEquals( 0.5, printSetup.getHeaderMargin(), 0.01 );
        assertEquals( 0.5, printSetup.getFooterMargin(), 0.01 );
        assertEquals( 0.75, sheet0.getMargin( Sheet.LeftMargin ), 0.01 );
        assertEquals( 0.75, sheet0.getMargin( Sheet.RightMargin ), 0.01 );
        assertEquals( 1.0, sheet0.getMargin( Sheet.TopMargin ), 0.01 );
        assertEquals( 1.0, sheet0.getMargin( Sheet.BottomMargin ), 0.01 );

    } finally {
        inputStream.close();
    }
}
项目:fenixedu-commons    文件:StyledExcelSpreadsheet.java   
public void setSheetOrientation() {
    HSSFPrintSetup ps = getSheet().getPrintSetup();
    ps.setLandscape(true);
    getSheet().setMargin(HSSFSheet.TopMargin, 0.10);
    getSheet().setMargin(HSSFSheet.BottomMargin, 0.10);
    getSheet().setMargin(HSSFSheet.LeftMargin, 0.10);
    getSheet().setMargin(HSSFSheet.RightMargin, 0.10);
}
项目:hy.common.report    文件:ExcelHelp.java   
/**
 * 复制模板工作表的打印区域到数据工作表中
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-17
 * @version     v1.0
 * 
 * @param i_FromSheet  源工作表
 * @param i_ToSheet    目标工作表
 */
public final static void copyPrintSetup(Sheet i_FromSheet ,Sheet i_ToSheet) 
{
    PrintSetup v_FromPrintSetup = i_FromSheet.getPrintSetup();
    PrintSetup v_ToPrintSetup   = i_ToSheet  .getPrintSetup();

    v_ToPrintSetup.setCopies(       v_FromPrintSetup.getCopies());
    v_ToPrintSetup.setDraft(        v_FromPrintSetup.getDraft());          // 值为true时,表示用草稿品质打印
    v_ToPrintSetup.setFitHeight(    v_FromPrintSetup.getFitHeight());      // 设置页高
    v_ToPrintSetup.setFitWidth(     v_FromPrintSetup.getFitWidth());       // 设置页宽
    v_ToPrintSetup.setFooterMargin( v_FromPrintSetup.getFooterMargin());
    v_ToPrintSetup.setHeaderMargin( v_FromPrintSetup.getHeaderMargin());
    v_ToPrintSetup.setHResolution(  v_FromPrintSetup.getHResolution());
    v_ToPrintSetup.setLandscape(    v_FromPrintSetup.getLandscape());      // true,则表示页面方向为横向;否则为纵向
    v_ToPrintSetup.setLeftToRight(  v_FromPrintSetup.getLeftToRight());    // true表示“先行后列”;false表示“先列后行”
    v_ToPrintSetup.setNoColor(      v_FromPrintSetup.getNoColor());        // 值为true时,表示单色打印
    v_ToPrintSetup.setNoOrientation(v_FromPrintSetup.getNoOrientation()); 
    v_ToPrintSetup.setNotes(        v_FromPrintSetup.getNotes());          // 设置打印批注
    v_ToPrintSetup.setPageStart(    v_FromPrintSetup.getPageStart());      // 设置打印起始页码
    v_ToPrintSetup.setPaperSize(    v_FromPrintSetup.getPaperSize());      // 纸张类型 A4纸 HSSFPrintSetup.A4_PAPERSIZE
    v_ToPrintSetup.setScale(        v_FromPrintSetup.getScale());          // 缩放比例80%(设置为0-100之间的值)
    v_ToPrintSetup.setUsePage(      v_FromPrintSetup.getUsePage());        // 设置打印起始页码是否使用"自动"
    v_ToPrintSetup.setValidSettings(v_FromPrintSetup.getValidSettings());
    v_ToPrintSetup.setVResolution(  v_FromPrintSetup.getVResolution());

    // 设置打印参数
    if ( i_ToSheet instanceof HSSFSheet )
    {
        ((HSSFPrintSetup)v_ToPrintSetup).setOptions(((HSSFPrintSetup)v_FromPrintSetup).getOptions());

        i_ToSheet.setMargin(HSSFSheet.TopMargin     ,i_FromSheet.getMargin(HSSFSheet.TopMargin));     // 页边距(上)
        i_ToSheet.setMargin(HSSFSheet.BottomMargin  ,i_FromSheet.getMargin(HSSFSheet.BottomMargin));  // 页边距(下)
        i_ToSheet.setMargin(HSSFSheet.LeftMargin    ,i_FromSheet.getMargin(HSSFSheet.LeftMargin));    // 页边距(左)
        i_ToSheet.setMargin(HSSFSheet.RightMargin   ,i_FromSheet.getMargin(HSSFSheet.RightMargin));   // 页边距(右)
        i_ToSheet.setMargin(HSSFSheet.HeaderMargin  ,i_FromSheet.getMargin(HSSFSheet.HeaderMargin));  // 页眉
        i_ToSheet.setMargin(HSSFSheet.FooterMargin  ,i_FromSheet.getMargin(HSSFSheet.FooterMargin));  // 页脚
    }
    else if ( i_ToSheet instanceof SXSSFSheet )
    {
        ((XSSFPrintSetup)v_ToPrintSetup).setOrientation(((XSSFPrintSetup)v_FromPrintSetup).getOrientation());  // 设置方向 

        i_ToSheet.setMargin(SXSSFSheet.TopMargin    ,i_FromSheet.getMargin(SXSSFSheet.TopMargin));     // 页边距(上)
        i_ToSheet.setMargin(SXSSFSheet.BottomMargin ,i_FromSheet.getMargin(SXSSFSheet.BottomMargin));  // 页边距(下)
        i_ToSheet.setMargin(SXSSFSheet.LeftMargin   ,i_FromSheet.getMargin(SXSSFSheet.LeftMargin));    // 页边距(左)
        i_ToSheet.setMargin(SXSSFSheet.RightMargin  ,i_FromSheet.getMargin(SXSSFSheet.RightMargin));   // 页边距(右)
        i_ToSheet.setMargin(SXSSFSheet.HeaderMargin ,i_FromSheet.getMargin(SXSSFSheet.HeaderMargin));  // 页眉
        i_ToSheet.setMargin(SXSSFSheet.FooterMargin ,i_FromSheet.getMargin(SXSSFSheet.FooterMargin));  // 页脚
    }
    else if ( i_ToSheet instanceof XSSFSheet )
    {
        ((XSSFPrintSetup)v_ToPrintSetup).setOrientation(((XSSFPrintSetup)v_FromPrintSetup).getOrientation());  // 设置方向 

        i_ToSheet.setMargin(XSSFSheet.TopMargin     ,i_FromSheet.getMargin(XSSFSheet.TopMargin));     // 页边距(上)
        i_ToSheet.setMargin(XSSFSheet.BottomMargin  ,i_FromSheet.getMargin(XSSFSheet.BottomMargin));  // 页边距(下)
        i_ToSheet.setMargin(XSSFSheet.LeftMargin    ,i_FromSheet.getMargin(XSSFSheet.LeftMargin));    // 页边距(左)
        i_ToSheet.setMargin(XSSFSheet.RightMargin   ,i_FromSheet.getMargin(XSSFSheet.RightMargin));   // 页边距(右)
        i_ToSheet.setMargin(XSSFSheet.HeaderMargin  ,i_FromSheet.getMargin(XSSFSheet.HeaderMargin));  // 页眉
        i_ToSheet.setMargin(XSSFSheet.FooterMargin  ,i_FromSheet.getMargin(XSSFSheet.FooterMargin));  // 页脚
    }

    copyHeaderFooter(i_FromSheet.getHeader() ,i_ToSheet.getHeader());
    copyHeaderFooter(i_FromSheet.getFooter() ,i_ToSheet.getFooter());
}
项目:ureport    文件:Excel97Producer.java   
private boolean setupPaper(PaperType paperType, HSSFPrintSetup printSetup) {
    boolean setup=false;
    switch(paperType){
        case A0:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case A1:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case A2:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case A3:                
            printSetup.setPaperSize(HSSFPrintSetup.A3_PAPERSIZE);
            setup=true;
            break;
        case A4:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            setup=true;
            break;
        case A5:
            printSetup.setPaperSize(HSSFPrintSetup.A5_PAPERSIZE);
            setup=true;
            break;
        case A6:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case A7:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case A8:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case A9:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case A10:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B0:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B1:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B2:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B3:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B4:
            printSetup.setPaperSize(HSSFPrintSetup.B4_PAPERSIZE);
            setup=true;
            break;
        case B5:
            printSetup.setPaperSize(HSSFPrintSetup.B5_PAPERSIZE);
            setup=true;
            break;
        case B6:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B7:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B8:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B9:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case B10:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
        case CUSTOM:
            printSetup.setPaperSize(HSSFPrintSetup.A4_EXTRA_PAPERSIZE);
            break;
    }
    return setup;
}
项目:jasperreports    文件:JRXlsMetadataExporter.java   
private final short getSuitablePaperSize() {

        if (pageFormat == null) {
            return -1;
        }
        long width = 0;
        long height = 0;
        short ps = -1;

        if ((pageFormat.getPageWidth() != 0) && (pageFormat.getPageHeight() != 0)) {

            double dWidth = (pageFormat.getPageWidth() / 72.0);
            double dHeight = (pageFormat.getPageHeight() / 72.0);

            height = Math.round(dHeight * 25.4);
            width = Math.round(dWidth * 25.4);

            // Compare to ISO 216 A-Series (A3-A5). All other ISO 216 formats
            // not supported by POI Api yet.
            // A3 papersize also not supported by POI Api yet.
            for (int i = 4; i < 6; i++) {
                int w = calculateWidthForDinAN(i);
                int h = calculateHeightForDinAN(i);

                if (((w == width) && (h == height)) || ((h == width) && (w == height))) {
                    if (i == 4) {
                        ps = HSSFPrintSetup.A4_PAPERSIZE;
                    } else if (i == 5) {
                        ps = HSSFPrintSetup.A5_PAPERSIZE;
                    }
                    break;
                }
            }

            //envelope sizes
            if (ps == -1) {
                // ISO 269 sizes - "Envelope DL" (110 x 220 mm)
                if (((width == 110) && (height == 220)) || ((width == 220) && (height == 110))) {
                    ps = HSSFPrintSetup.ENVELOPE_DL_PAPERSIZE;
                }
            }

            // Compare to common North American Paper Sizes (ANSI X3.151-1987).
            if (ps == -1) {
                // ANSI X3.151-1987 - "Letter" (216 x 279 mm)
                if (((width == 216) && (height == 279)) || ((width == 279) && (height == 216))) {
                    ps = HSSFPrintSetup.LETTER_PAPERSIZE;
                }
                // ANSI X3.151-1987 - "Legal" (216 x 356 mm)
                if (((width == 216) && (height == 356)) || ((width == 356) && (height == 216))) {
                    ps = HSSFPrintSetup.LEGAL_PAPERSIZE;
                }
                // ANSI X3.151-1987 - "Executive" (190 x 254 mm)
                else if (((width == 190) && (height == 254)) || ((width == 254) && (height == 190))) {
                    ps = HSSFPrintSetup.EXECUTIVE_PAPERSIZE;
                }
                // ANSI X3.151-1987 - "Ledger/Tabloid" (279 x 432 mm)
                // Not supported by POI Api yet.
            }
        }
        return ps;
    }
项目:ryf_mms2    文件:DownloadFileService.java   
/**
 * 为退款经办下载表
 * 
 * @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());
}
项目:metasfresh    文件:PrintDataExcelExporter.java   
@Override
protected void formatPage(final HSSFSheet sheet)
{
    super.formatPage(sheet);
    MPrintPaper paper = MPrintPaper.get(this.m_printFormat.getAD_PrintPaper_ID());
    //
    // Set paper size:
    short paperSize = -1;
    MediaSizeName mediaSizeName = paper.getMediaSize().getMediaSizeName();
    if (MediaSizeName.NA_LETTER.equals(mediaSizeName))
    {
        paperSize = HSSFPrintSetup.LETTER_PAPERSIZE;
    }
    else if (MediaSizeName.NA_LEGAL.equals(mediaSizeName))
    {
        paperSize = HSSFPrintSetup.LEGAL_PAPERSIZE;
    }
    else if (MediaSizeName.EXECUTIVE.equals(mediaSizeName))
    {
        paperSize = HSSFPrintSetup.EXECUTIVE_PAPERSIZE;
    }
    else if (MediaSizeName.ISO_A4.equals(mediaSizeName))
    {
        paperSize = HSSFPrintSetup.A4_PAPERSIZE;
    }
    else if (MediaSizeName.ISO_A5.equals(mediaSizeName))
    {
        paperSize = HSSFPrintSetup.A5_PAPERSIZE;
    }
    else if (MediaSizeName.NA_NUMBER_10_ENVELOPE.equals(mediaSizeName))
    {
        paperSize = HSSFPrintSetup.ENVELOPE_10_PAPERSIZE;
    }
    // else if (MediaSizeName..equals(mediaSizeName)) {
    // paperSize = HSSFPrintSetup.ENVELOPE_DL_PAPERSIZE;
    // }
    // else if (MediaSizeName..equals(mediaSizeName)) {
    // paperSize = HSSFPrintSetup.ENVELOPE_CS_PAPERSIZE;
    // }
    else if (MediaSizeName.MONARCH_ENVELOPE.equals(mediaSizeName))
    {
        paperSize = HSSFPrintSetup.ENVELOPE_MONARCH_PAPERSIZE;
    }
    if (paperSize != -1)
    {
        sheet.getPrintSetup().setPaperSize(paperSize);
    }
    //
    // Set Landscape/Portrait:
    sheet.getPrintSetup().setLandscape(paper.isLandscape());
    //
    // Set Paper Margin:
    sheet.setMargin(HSSFSheet.TopMargin, ((double)paper.getMarginTop()) / 72);
    sheet.setMargin(HSSFSheet.RightMargin, ((double)paper.getMarginRight()) / 72);
    sheet.setMargin(HSSFSheet.LeftMargin, ((double)paper.getMarginLeft()) / 72);
    sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72);
    //
}