本文整理了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>()
方法的一些代码示例,展示了HSSFWorkbook.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFWorkbook.<init>()
方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFWorkbook
类名称:HSSFWorkbook
方法名:<init>
[英]Creates new HSSFWorkbook from scratch (start here!)
[中]从头开始创建新的HSSF工作簿(从这里开始!)
代码示例来源:origin: stackoverflow.com
Workbook wb = new HSSFWorkbook();
//Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow((short)0);
// Create a cell and put a value in it.
Cell cell = row.createCell(0);
cell.setCellValue(1);
// Or do it on one line.
row.createCell(1).setCellValue(1.2);
row.createCell(2).setCellValue(
createHelper.createRichTextString("This is a string"));
row.createCell(3).setCellValue(true);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
代码示例来源: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
FileInputStream fis = new FileInputStream("/somepath/test.xls");
Workbook wb = new HSSFWorkbook(fis); //or new XSSFWorkbook("/somepath/test.xls")
Sheet sheet = wb.getSheetAt(0);
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
代码示例来源:origin: stackoverflow.com
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
HSSFSheet s = wb.getSheetAt(0);
s.setActive(true);
HSSFRow row = s.getRow(0);
HSSFCell cell = row.getCell(0);
cell.setAsActiveCell();
FileOutputStream out = new FileOutputStream(file);
代码示例来源:origin: stackoverflow.com
InputStream is = new FileInputStream(FILEPATH);
HSSFWorkbook wb = new HSSFWorkbook(is);
ByteArrayOutputStream out = new ByteArrayOutputStream();
wb.write(out);
HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
代码示例来源:origin: stackoverflow.com
HSSFWorkbook wb;
HSSFSheet sheet;
if(file.exists()) {//The workbook has been created already
wb = (HSSFWorkbook) WorkbookFactory.create(new FileInputStream(file));//Line 1
sheet = wb.getSheetAt(0);
} else {//No workbook exists at the location the "file" specifies
wb = new HSSFWorkbook();
sheet = wb.createSheet();
}
代码示例来源:origin: org.apache.poi/poi-examples
public static void main(String[] args) throws IOException {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {
wb.write(fileOut);
}
}
}
}
代码示例来源: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
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 hwb = new HSSFWorkbook();
...
OutputStream outStream = response.getOutputStream();
hwb.write(outputStream);
....
代码示例来源:origin: org.apache.poi/poi
} else {
System.out.print("reading " + filename + "...");
FileInputStream is = new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(is);
try {
System.out.println("done");
String outputFile = filename.replace(".xls", "-saved.xls");
System.out.print("saving to " + outputFile + "...");
os = new FileOutputStream(outputFile);
wb.write(os);
} finally {
os.close();
代码示例来源:origin: org.apache.poi/poi
is = System.in;
} else {
is = new FileInputStream(cmdArgs.getInputFile());
HSSFWorkbook wb = new HSSFWorkbook(is);
is.close();
代码示例来源:origin: stackoverflow.com
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import au.com.bytecode.opencsv.CSVReader;
class Test {
public static void main(String[] args) throws IOException {
Workbook wb = new HSSFWorkbook();
CreationHelper helper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
CSVReader reader = new CSVReader(new FileReader("data.csv"));
String[] line;
int r = 0;
while ((line = reader.readNext()) != null) {
Row row = sheet.createRow((short) r++);
for (int i = 0; i < line.length; i++)
row.createCell(i)
.setCellValue(helper.createRichTextString(line[i]));
}
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}
代码示例来源:origin: stackoverflow.com
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = new HSSFSheet();
Header header = sheet.getHeader() //get header from workbook's sheet
header.setCenter(HSSFHeader.font("COURIER", "Normal")+ HSSFHeader.fontSize((short) 15) + "Hello world" +new Date()); // set header with desire font style
FileOutputStream fileOut = new FileOutputStream("C:\\book.xls");
workbook.write(fileOut);
代码示例来源: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: 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
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
...
OutputStream out = response.getOutputStream();
wb.write(out);
out.close();
代码示例来源:origin: youseries/ureport
private void doProduce(Report report, OutputStream outputStream,boolean withPaging,boolean withSheet) {
CellStyleContext cellStyleContext=new CellStyleContext();
HSSFWorkbook wb = new HSSFWorkbook();
CreationHelper creationHelper=wb.getCreationHelper();
Paper paper=report.getPaper();
wb.write(outputStream);
}catch(Exception ex){
throw new ReportComputeException(ex);
代码示例来源: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();
内容来源于网络,如有侵权,请联系作者删除!