本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFWorkbook.createSheet方法的具體用法?Java HSSFWorkbook.createSheet怎麽用?Java HSSFWorkbook.createSheet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.createSheet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeXLSFile
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public static void writeXLSFile() throws IOException {
HSSFWorkbook wbObj = new HSSFWorkbook();
HSSFSheet sheet = wbObj.createSheet(sheetName);
for (int row = 0; row < tableData.size(); row++) {
HSSFRow rowObj = sheet.createRow(row);
rowData = tableData.get(row);
for (int col = 0; col < rowData.size(); col++) {
HSSFCell cellObj = rowObj.createCell(col);
cellObj.setCellValue(rowData.get(col));
}
}
FileOutputStream fileOut = new FileOutputStream(excelFileName);
wbObj.write(fileOut);
wbObj.close();
fileOut.flush();
fileOut.close();
}
示例2: createWorkbook
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private HSSFWorkbook createWorkbook() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
// Add dummy lines
sheet.createRow(0).createCell(0).setCellValue("First dummy row");
sheet.createRow(1).createCell(0).setCellValue("Second dummy row");
HSSFRow row = sheet.createRow(2);
row.createCell(13).setCellValue("BoundaryPoint FR-BE");
row.createCell(14).setCellValue("France");
row.createCell(15).setCellValue("Belgium");
return workbook;
}
示例3: getXLS
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* Creates XLS document from given list of {@link PollOption} objects.
*
* @param results List of {@link PollOption} objects.
* @return XLS document.
*/
public static HSSFWorkbook getXLS(List<PollOption> results) {
HSSFWorkbook document = new HSSFWorkbook();
HSSFSheet sheet = document.createSheet("Results");
HSSFRow rowhead = sheet.createRow(0);
rowhead.createCell(0).setCellValue("Ime opcije:");
rowhead.createCell(1).setCellValue("Broj glasova:");
for (int i = 0; i < results.size(); i++) {
HSSFRow row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(results.get(i).getName());
row.createCell(1).setCellValue(
Double.valueOf(results.get(i).getVotes()));
}
return document;
}
示例4: getXLS
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* Creates XLS document based on given input parameters.
*
* @param a Start number.
* @param b End number.
* @param n Last power.
* @return Created XLS document.
*/
private HSSFWorkbook getXLS(Integer a, Integer b, Integer n) {
HSSFWorkbook workbook = new HSSFWorkbook();
for (int i = 1; i <= n; i++) {
HSSFSheet sheet = workbook.createSheet(i + "-th power.");
HSSFRow rowHead = sheet.createRow(0);
rowHead.createCell(0).setCellValue("x");
rowHead.createCell(1).setCellValue("x^" + i);
int rowCounter = 1;
for (int j = a; j <= b; j++) {
HSSFRow row = sheet.createRow(rowCounter++);
row.createCell(0).setCellValue(Double.valueOf(j));
row.createCell(1).setCellValue(Math.pow(Double.valueOf(j), i));
}
}
return workbook;
}
示例5: getXLS
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* Creates XLS document based from given list of bands.
*
* @param results List of bands.
* @return XLS document.
*/
public static HSSFWorkbook getXLS(List<Band> results) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Voting results");
HSSFRow rowHead = sheet.createRow(0);
rowHead.createCell(0).setCellValue("Band name:");
rowHead.createCell(1).setCellValue("Number of votes:");
for (int i = 0, size = results.size(); i < size; i++) {
HSSFRow row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(results.get(i).getName());
row.createCell(1).setCellValue(
Double.valueOf(results.get(i).getVotes()));
}
return workbook;
}
示例6: createSheet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
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;
}
示例7: exportTables
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void exportTables(List<String> tables, final String fileName) throws Exception {
workbook = new HSSFWorkbook();
for (int i = 0; i < tables.size(); i++) {
if (!tables.get(i).equals("android_metadata")) {
HSSFSheet sheet = workbook.createSheet(tables.get(i));
createSheet(tables.get(i), sheet);
}
}
File file = new File(mExportPath, fileName);
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
fos.flush();
fos.close();
workbook.close();
database.close();
}
示例8: beforeClass
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
@BeforeClass
public static void beforeClass() {
workbook = new HSSFWorkbook();
sheet = workbook.createSheet("Default");
Row row = sheet.createRow(ypos++);
CellStyle style = workbook.createCellStyle();
style.setWrapText(true);
setCell(style, row, 1, "Bytes\nSize");
setCell(style, row, 2, "Serialization\nRaw");
setCell(style, row, 3, "Externalizor\nRaw");
setCell(style, row, 4, "Serialization\nCompressed");
setCell(style, row, 5, "Externalizor\nCompressed");
setCell(style, row, 7, "Rate\nrw / sec");
setCell(style, row, 8, "Serialization\nRaw");
setCell(style, row, 9, "Externalizor\nRaw");
setCell(style, row, 10, "Serialization\nCompressed");
setCell(style, row, 11, "Externalizor\nCompressed");
}
示例9: export
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private Workbook export() throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
first = 0;
pageSize= 10;
workbook = new HSSFWorkbook(); //XSSFWorkbook(); //HSSFWorkbook();
Sheet sheet = workbook.createSheet( "export" );
List<T> list = loadNext();
int nrow = 1; // 2 righe sono lasciate per l'header
if ( list != null && !list.isEmpty() )
{
while ( list != null && !list.isEmpty() )
{
for ( T obj : list )
{
nrow++;
Row row = sheet.createRow( nrow );
exported.clear();
export( row, 0, obj );
}
list = loadNext();
}
exportHeaders( sheet );
}
return workbook;
}
示例10: write
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public void write(String src) throws IOException{
System.out.println(src);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Resultats");
for (int i=0; i<size(); i++) {
HSSFRow row = sheet.createRow(i);
HSSFCell cell = row.createCell(0);
cell.setCellValue(get(i).area());
}
FileOutputStream fileOut;
fileOut = new FileOutputStream(src);
wb.write(fileOut);
fileOut.close();
}
示例11: dataToWorkbook
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* 將數據寫入workbook
* @param workbook 不傳遞則創建一個workbook
* @param sheetName 為null則默認為"自動導出"
* @return
*/
public HSSFWorkbook dataToWorkbook(HSSFWorkbook workbook, String sheetName) {
if (init()) {
HSSFWorkbook wbook = workbook == null ? new HSSFWorkbook() : workbook;
// 創建一個sheet
sheetName = (sheetName == null ? "自動導出" : sheetName);
HSSFSheet sheet = wbook.createSheet(sheetName);
//寫入表頭條件
writeCondtions(sheet);
// 寫入標題
writeHead(sheet);
// 寫入內容
writeBody(sheet);
autoSheetWidth(sheet);
completeAfter(sheet);
return wbook;
}
return null;
}
示例12: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get data model which is passed by the Spring container
List<RatingCountBean> listOfRating = (List<RatingCountBean>) model.get("listOfRatingCount");
// create a new Excel sheet
HSSFSheet sheet = workbook.createSheet("Feedback Report");
sheet.setDefaultColumnWidth(30);
// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);
// create header row
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Question Number");
header.getCell(0).setCellStyle(style);
header.createCell(1).setCellValue("Question");
header.getCell(1).setCellStyle(style);
header.createCell(2).setCellValue("Very Poor");
header.getCell(2).setCellStyle(style);
header.createCell(3).setCellValue("Poor");
header.getCell(3).setCellStyle(style);
header.createCell(4).setCellValue("Good");
header.getCell(4).setCellStyle(style);
header.createCell(5).setCellValue("Best");
header.getCell(5).setCellStyle(style);
header.createCell(6).setCellValue("Excellent");
header.getCell(6).setCellStyle(style);
// create data rows
int rowCount = 1;
for (RatingCountBean rating : listOfRating) {
HSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(rating.getQuestionId());
aRow.createCell(1).setCellValue(rating.getQuestionText());
aRow.createCell(2).setCellValue(rating.getRating_one_total_count());
aRow.createCell(3).setCellValue(rating.getRating_two_total_count());
aRow.createCell(4).setCellValue(rating.getRating_three_total_count());
aRow.createCell(5).setCellValue(rating.getRating_four_total_count());
aRow.createCell(6).setCellValue(rating.getRating_five_total_count());
}
}
示例13: createSheet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
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;
}
示例14: test_001
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的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版本的單元格顏色");
}
示例15: create
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public List<Sheet> create(String... sheetName) {
wb = new HSSFWorkbook();
List<Sheet> listSheet = new ArrayList<Sheet>();
for (String name : sheetName) {
@SuppressWarnings("unused")
Sheet sheet = wb.createSheet(name);
listSheet.add(sheet);
}
save();
return listSheet;
}