org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet()方法的一些代码示例,展示了HSSFWorkbook.createSheet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFWorkbook.createSheet()方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFWorkbook
类名称:HSSFWorkbook
方法名:createSheet

HSSFWorkbook.createSheet介绍

[英]create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation. Use this to create new sheets.
[中]为此HSSF工作簿创建HSSF表,将其添加到工作表中并返回高级表示。使用此选项可以创建新图纸。

代码示例

代码示例来源:origin: stackoverflow.com

public void getReportData() throws IOException {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet = workbook.createSheet();
  HSSFRow row = sheet.createRow(0);
  HSSFCell cell = row.createCell(0);
  cell.setCellValue(0.0);

  FacesContext facesContext = FacesContext.getCurrentInstance();
  ExternalContext externalContext = facesContext.getExternalContext();
  externalContext.setResponseContentType("application/vnd.ms-excel");
  externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"my.xls\"");

  workbook.write(externalContext.getResponseOutputStream());
  facesContext.responseComplete();
}

代码示例来源:origin: pentaho/pentaho-kettle

private HSSFWorkbook createWorkbook( FileObject file ) throws Exception {
 HSSFWorkbook wb = null;
 OutputStream os = null;
 try {
  os = file.getContent().getOutputStream();
  wb = new HSSFWorkbook();
  wb.createSheet( SHEET_NAME );
  wb.write( os );
 } finally {
  os.flush();
  os.close();
 }
 return wb;
}

代码示例来源:origin: stackoverflow.com

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
sheet = wb.getSheetAt(0);

for (Row myrow : sheet) {
  for (Cell mycell : myrow) {
    //set foreground color here
  }
}

代码示例来源:origin: stackoverflow.com

HSSFWorkbook workbook=new HSSFWorkbook();
     HSSFSheet sheet =  workbook.createSheet("FirstSheet");  
     HSSFRow rowhead=   sheet.createRow((short)0);
     HSSFCellStyle style = workbook.createCellStyle();
     style.setWrapText(true);
     row.setRowStyle(style);
     row.getCell(0).setCellStyle(style);

代码示例来源:origin: stackoverflow.com

public void setExcelRows(HSSFWorkbook wb, List<Employee> empList) {
 int record = 1; int sheetNum = 0;
 HSSFSheet sheet = wb.createSheet("Employee List "+sheetNum);
 setExcelHeader(sheet);
 for (Employee a : empList) {
    if (record == 26){
      sheetNum++;
      sheet= wb.createSheet("Employee List "+ sheetNum);
      setExcelHeader(sheet);
      record = 1;
    }        
    HSSFRow excelRow = sheet.createRow(record++);
   excelRow.createCell(1).setCellValue(a.getId());
}

代码示例来源:origin: stackoverflow.com

File destFile = new File("/test.xls");
FileInputStream fileStream = new FileInputStream(destFile);
POIFSFileSystem fsPoi = new POIFSFileSystem(fileStream);

HSSFWorkbook workbook = new HSSFWorkbook(fsPoi);

int index = 0;

HSSFSheet sheet = workbook.getSheet("Setup");
if(sheet != null)   {
  index = workbook.getSheetIndex(sheet);
  workbook.removeSheetAt(index);
}
workbook.createSheet("Setup");
FileOutputStream output = new FileOutputStream(destFile);
workbook.write(output);
output.close();

代码示例来源:origin: stackoverflow.com

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet realSheet = workbook.createSheet("Sheet xls");
HSSFSheet hidden = workbook.createSheet("hidden");
for (int i = 0, length= countryName.length; i < length; i++) {
  String name = countryName[i];
  HSSFRow row = hidden.createRow(i);
  HSSFCell cell = row.createCell(0);
  cell.setCellValue(name);
 }
 Name namedCell = workbook.createName();
 namedCell.setNameName("hidden");
 namedCell.setRefersToFormula("hidden!$A$1:$A$" + countryName.length);
 DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden");
 CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
 HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint);
 workbook.setSheetHidden(1, true);
 realSheet.addValidationData(validation);
 FileOutputStream stream = new FileOutputStream("c:\\range.xls");
 workbook.write(stream);
 stream.close();

代码示例来源:origin: stackoverflow.com

// Set up a rudimentary worksheet with a cell in it
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(“sheet1”);
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);

// Set up fonts
HSSFFont blueFont = workbook.createFont();
blueFont.setColor(HSSFColor.BLUE.index);

HSSFFont greenFont = workbook.createFont();
greenFont.setColor(HSSFColor.GREEN.index);

// create a cell style and assign the first font to it
HSSFCellStyle style = workbook.createCellStyle();
style.setFont(blueFont);

// assign the style to the cell
cell.setCellStyle(style);

// override the parts of the text that you want to
// color differently by applying a different font.
HSSFRichTextString richString = new HSSFRichTextString("Hello, World!");
richString.applyFont(6, 13, greenFont);
cell.setCellValue(richString);

代码示例来源:origin: stackoverflow.com

private void createExcelFile() {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sampleDataSheet1 = workbook.createSheet("ABC");
  HSSFSheet sampleDataSheet2 = workbook.createSheet("XYZ");
  // save to disk
}

代码示例来源:origin: stackoverflow.com

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
...
OutputStream out = response.getOutputStream();
wb.write(out);
out.close();

代码示例来源:origin: ckpoint/CheckPoint

private void init(PoiWorkBook workBook, String sheetName) {
  this.style = new PoiCellStyle(workBook);
  if (sheetName != null) {
    this.sheet = workBook.getWorkBook().createSheet(this.checkSheetName(sheetName));
  } else {
    this.sheet = workBook.getWorkBook().createSheet();
  }
  this.sheet.createRow(0);
}

代码示例来源:origin: stackoverflow.com

try {
  String filename = "C:/NewExcelFile.xls" ;
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet = workbook.createSheet("FirstSheet");  
  HSSFRow rowhead = sheet.createRow((short)0);
  rowhead.createCell(0).setCellValue("No.");
  rowhead.createCell(1).setCellValue("Name");
  rowhead.createCell(3).setCellValue("Email");
  HSSFRow row = sheet.createRow((short)1);
  row.createCell(0).setCellValue("1");
  row.createCell(1).setCellValue("Sankumarsingh");
  workbook.write(fileOut);
  fileOut.close();
  System.out.println("Your excel file has been generated!");

代码示例来源:origin: stackoverflow.com

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//..
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sample sheet");
//Create a new row in current sheet
Row row = sheet.createRow(0);
//Create a new cell in current row
Cell cell = row.createCell(0);
//Set value to new value
cell.setCellValue("Blahblah");

代码示例来源:origin: org.wicketstuff/wicket-poi

/**
 * Create the sheet in where component table data will be set
 * 
 * @return a new {@link Sheet} to receive the table component data
 */
protected Sheet newSheet()
{
  return new HSSFWorkbook().createSheet("data");
}

代码示例来源:origin: stackoverflow.com

FileOutputStream archivoSalida;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sht = wb.createSheet("Conciliacion");
...
...
archivoSalida = new FileOutputStream(fileDestination);
wb.write(archivoSalida);
archivoSalida.close();

代码示例来源:origin: stackoverflow.com

HSSFWorkbook workbook = new XSSFWorkbook(); 

// Cell styles. Note the setLocked(true) method call. 
HSSFCellStyle lockedNumericStyle = workbook.createCellStyle(); 
lockedNumericStyle.setAlignment(XSSFCellStyle.ALIGN_RIGHT); 
lockedNumericStyle.setLocked(true); 

HSSFSheet sheet = workbook.createSheet("Protection Test"); 
HSSFRow row = sheet.createRow(0); 
HSSFCell cell = row.createCell(0); 
cell.setCellValue(100); 
cell.setCellStyle(lockedNumericStyle); 

// This line should cause all locked cells to be protected, 
// the user should not be able to change the cells 
// contents. 
sheet.protectSheet("password"); 

The password makes it possible to remove the protection from the sheet and makes it possible then for the locked cells to be modified.

代码示例来源:origin: stackoverflow.com

HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet =  hwb.createSheet("new sheet");
  HSSFRow row = sheet.createRow(rowNum);
  row.createCell(0).setValue("col0");
  row.createCell(1).setValue("col1");
hwb.write(baos);
excelStream = new ByteArrayInputStream(baos.toByteArray());

代码示例来源:origin: stackoverflow.com

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//..
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sample sheet");
//Create a new row in current sheet
Row row = sheet.createRow(0);
//Create a new cell in current row
Cell cell = row.createCell(0);
//Set value to new value
cell.setCellValue("Blahblah");

代码示例来源:origin: com.haulmont.cuba/cuba-gui

protected void createWorkbookWithSheet() {
  wb = new HSSFWorkbook();
  sheet = wb.createSheet("Export");
}

代码示例来源:origin: stackoverflow.com

private static void writeToSpreadSheet(String test,
    Map<String, String> errorMap, Object object) throws IOException {
  // Creating the new workbook every time you call this method
  HSSFWorkbook workbook = new HSSFWorkbook();

  // Adding the same sheet to newly created workbook
  HSSFSheet sheet = workbook.createSheet(test);
  FileOutputStream fis = new FileOutputStream("output/test.xls");
  // causing to overwrite your old workbook
  workbook.write(fis);
  if (fis != null)
    fis.close();
}

相关文章

HSSFWorkbook类方法