当前位置: 首页>>代码示例>>Java>>正文


Java Workbook类代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.Workbook的典型用法代码示例。如果您正苦于以下问题:Java Workbook类的具体用法?Java Workbook怎么用?Java Workbook使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Workbook类属于org.apache.poi.ss.usermodel包,在下文中一共展示了Workbook类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDown

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
@RequestMapping(value = "/test2.xlsx", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
byte[] testDown() throws IOException, InvalidFormatException {
    Workbook workbook = new SXSSFWorkbook();
    Sheet sheet = workbook.createSheet();
    for (int i = 0; i < 60000; i++) {
        Row newRow = sheet.createRow(i);
        for (int j = 0; j < 100; j++) {
            newRow.createCell(j).setCellValue("test" + Math.random());
        }
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    workbook.write(os);
    byte[] bytes = os.toByteArray();
    return bytes;
}
 
开发者ID:Yuiffy,项目名称:file-download-upload-zip-demo,代码行数:17,代码来源:FileController.java

示例2: defaultDataCellStyle

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
/**
 * Returns the default data cell style. Obtained from:
 * http://svn.apache.org/repos/asf/poi
 * /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
 *
 * @param wb the wb
 * @return the cell style
 */
protected CellStyle defaultDataCellStyle(final Workbook wb) {
    CellStyle style;
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setWrapText(true);
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(BorderStyle.THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(BorderStyle.THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    style.setDataFormat(doubleDataFormat);
    return style;
}
 
开发者ID:TFyre,项目名称:vaadin-gridexport,代码行数:25,代码来源:ExcelExport.java

示例3: createIndentationCellStyle

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
public CellStyle createIndentationCellStyle(Workbook workbook, int s) {
	CellStyle dataStyle1 = this.createBorderCellStyle(workbook, true);
	Font dataFont = workbook.createFont();
	dataFont.setColor((short) 12);
	dataFont.setFontHeightInPoints((short) 10);
	dataStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	dataStyle1.setFillForegroundColor((short) 11);
	dataStyle1.setFont(dataFont);
	dataStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
	dataStyle1.setAlignment(HorizontalAlignment.LEFT);
	dataStyle1.setIndention(Short.valueOf(String.valueOf((s))));
	return dataStyle1;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:14,代码来源:GridStyleBuilder.java

示例4: setCellStyleFont

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
public void setCellStyleFont(Workbook workbook, CellStyle style, int i) {
	Font font = workbook.createFont();
	if (i == 0) {
		// 正常
	} else if (i == 4) {
		// 下划线
		font.setUnderline(Font.U_SINGLE);
		style.setFont(font);
	} else if (i == 2) {
		// 倾斜
		font.setItalic(true);
		style.setFont(font);
	} else if (i == 1) {
		// 加粗
		font.setBold(true);
		style.setFont(font);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:19,代码来源:AbstractStyleBuilder.java

示例5: testExcel07

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
@Test
public void testExcel07() throws IOException{
	List<UserPlus> list = getData(0, 20000);
	Map<String, String> map = new HashMap<String,String>();
	map.put("msg", "用户信息导出报表");
	map.put("status", "导出成功");
	long start = System.currentTimeMillis();
	Workbook workbook = ExcelExportUtil.exportExcel07(UserPlus.class, list, map, true);
	long end = System.currentTimeMillis();
	System.out.println("耗时:" + (end - start ) + "毫秒");
	FileOutputStream outputStream = new FileOutputStream("D:/test/user.xlsx");
	workbook.write(outputStream);
	if(SXSSFWorkbook.class.equals(workbook.getClass())){
		SXSSFWorkbook wb = (SXSSFWorkbook)workbook;
		wb.dispose();
	}
	outputStream.flush();
	outputStream.close();
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:20,代码来源:TestUser.java

示例6: doCreateStyleMap

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
/** 实际创建CellStyle Map
 * @param workbook
 * @param exportInfo
 * @param isHead
 * @return
 */
private static Map<Field, CellStyle> doCreateStyleMap(Workbook workbook, ExportInfo exportInfo,boolean isHead) {
	Map<ExportCellStyleInfo, CellStyle> tempCacheMap = new HashMap<ExportCellStyleInfo, CellStyle>();
	Map<Field, CellStyle> styleMap = new HashMap<Field, CellStyle>();
	CellStyle style;
	for(Map.Entry<Field,ExportFieldInfo> entry : exportInfo.getFieldInfoMap().entrySet()){
		ExportCellStyleInfo styleInfo ;
		if(isHead){
			styleInfo = entry.getValue().getHeadStyle();
		}else{
			styleInfo = entry.getValue().getDataStyle();
		}
		if(!StringUtils.isEmpty(entry.getValue().getDataFormat())){
			//当存在格式化时,即使是来自通用的样式,但是格式不一样,所以需要new专属格式的样式
			//由于格式化属于专属,因此也不需要放到临时缓存map之中
			style = doCreateCellStyle(workbook,styleInfo,entry.getValue().getDataFormat());			
		}else{
			style = tempCacheMap.get(styleInfo);
			if(style == null){
				style = doCreateCellStyle(workbook,styleInfo,null);
				tempCacheMap.put(styleInfo, style);
			}
		}
		if(style != null ){
			styleMap.put(entry.getKey(),style);						
		}				
	}
	tempCacheMap.clear();
	return styleMap.isEmpty() ? null : styleMap;
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:36,代码来源:CellStyleUtils.java

示例7: test2

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
@Test
public void test2() throws IOException {
    User user = new User("小红", "女", new Date());
    user.setPet(new Pet("小猫", new Date()));
    user.setAge(90);
    user.setAddress("uiijji");
    List<User> list = new ArrayList<User>();
    list.add(user);
    Workbook workbook = new HSSFWorkbook();
    //        workbook
    File file = new File("C:\\Users\\h_kx1\\Desktop\\test.xls");
    OutputStream os = new FileOutputStream(file);

    WriteExcelUtils.writeWorkBook(workbook, list);
    WriteExcelUtils.writeWorkBookToExcel(workbook, os);
    CommonUtils.closeIOStream(null, os);
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:18,代码来源:TestBeanToMap.java

示例8: importExcel

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
public static <T>  ImportResult<T> importExcel(ExcelFileType fileType,InputStream inputStream,Class<T> clazz) throws Exception{
	if(importInfoMap.get(clazz) == null){//初始化信息
		initTargetClass(clazz);			
	}
	ImportInfo importInfo = importInfoMap.get(clazz);
	Integer headRow = importInfo.getHeadRow();
	Workbook workbook = createWorkbook(fileType, inputStream);
	
	int sheetNum = workbook.getNumberOfSheets();
	if(sheetNum < 1 ){
		return null;
	}
	Sheet sheet = workbook.getSheetAt(0);
	int rowCount = sheet.getPhysicalNumberOfRows();
	if(rowCount < (headRow+1)){//
		return null;
	}
	List<String> headNameList = createHeadNameList(sheet, headRow);
	return readData(clazz, importInfo, workbook,headNameList);
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:21,代码来源:ExcelImportUtil.java

示例9: batchesExport

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
/**
 * 分批写出20w条数据
 * 
 * @throws IOException 
 */
@Test
public void batchesExport() throws IOException {
	Map<String, String> map = new HashMap<String,String>();
	map.put("msg", "用户信息导出报表");
	map.put("status", "导出成功");
	
	Workbook workbook = null;
	//分两次写入20w条数据
	List<UserPlus> list;
	for(int i = 0 ; i < 2 ; i++){
		list = getData(i*100000, 100000);
		workbook = ExcelExportUtil.exportExcel03(UserPlus.class, list, map,workbook);
		
	}
	FileOutputStream outputStream = new FileOutputStream("D:/test/user1.xls");
	workbook.write(outputStream);
	outputStream.flush();
	outputStream.close();
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:25,代码来源:TestUser.java

示例10: separateSheet

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
/**@throws IOException 
 * @Excel(headRow=2,dataRow=5,sheetName="用户统计表",sheetSize=65536)
 * 分sheet测试  
 */
@Test
public void separateSheet() throws IOException {
	//获取10w条数据
	List<UserPlus> list = getData(0, 100000);
	Map<String, String> map = new HashMap<String,String>();
	map.put("msg", "用户信息导出报表");
	map.put("status", "导出成功");
	long start = System.currentTimeMillis();
	Workbook workbook = ExcelExportUtil.exportExcel03(UserPlus.class, list, map);
	long end = System.currentTimeMillis();
	System.out.println("耗时:" + (end - start ) + "毫秒");
	FileOutputStream outputStream = new FileOutputStream("D:/test/user.xls");
	workbook.write(outputStream);
	outputStream.flush();
	outputStream.close();
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:21,代码来源:TestUser.java

示例11: createExcel

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
/**
 * Creates an excel file to export message data.
 * The excel workbook will have several sheets named after the map key.
 * Each sheet of the file will have the default form:
 * <ul>
 * <li>Line 1 (Header): KEY | de | fr | more iso-language-codes ...</li>
 * <li>Line 2..n (Values): message.key | Deutsch | Francaise | other translation</li>
 * </ul>
 * The header columns are defined by the provided languages in the resources lists.
 * The concrete row and column numbers can be configured to match more requirements like comments.
 * 
 * @param input a list of message information to write to excel
 * @param output if you want to create xls (Excel 97-2003) files, DO NOT use BufferedOutputStream due to library
 *            issue.
 * @param format use constants FORMAT_EXCEL_97 or FORMAT_EXCEL_2007
 * @throws I18nException if a problem occures
 */
public void createExcel(Map<String, List<MessageResourceEntry>> input,
						OutputStream output,
						String format) throws I18nException
{
	Workbook wb = createWorkbook(format);
	for (Entry<String, List<MessageResourceEntry>> entry : input.entrySet())
	{
		createSheet(entry.getValue(), entry.getKey(), wb);
	}
	try
	{
		LOG.info("Write data to output stream");
		wb.write(output);
	}
	catch (IOException e)
	{
		throw new I18nException("Problem writing to stream", e);
	}
}
 
开发者ID:namics,项目名称:spring-i18n-support,代码行数:37,代码来源:ExcelWriter.java

示例12: createExcel_keyFoundInDefaultProperty

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
@Test
public void createExcel_keyFoundInDefaultProperty() throws Exception {
    // given

    List<String> keyList = new ArrayList<String>();
    keyList.add(KEY1);
    Map<String, Properties> localizedProperties = prepareProperties(null,
            KEY2, VALUE + "2");
    Map<String, ResourceBundle> defaultProperties = prepareDefaultProperties(
            null, KEY1, VALUE + "1");
    List<Locale> locales = prepareLocaleList(null);
    prepareFacesContextStub(Locale.GERMAN, Locale.ENGLISH);
    // when
    Workbook result = ExcelHandler.createExcel(keyList, defaultProperties,
            localizedProperties, null,
            BaseBean.LABEL_USERINTERFACE_TRANSLARIONS, locales);
    // then
    verifyCreatedResult(result, "User interface",
            "Add your language code here");
    assertEquals(VALUE + "1", result.getSheetAt(0).getRow(1).getCell(1)
            .getStringCellValue());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:ExcelHandlerTest.java

示例13: createExcel_keyNotFoundInDefaultProperty

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
@Test
public void createExcel_keyNotFoundInDefaultProperty() throws Exception {
    // given

    List<String> keyList = new ArrayList<String>();
    keyList.add(KEY1);
    Map<String, Properties> localizedProperties = prepareProperties(null,
            KEY2, VALUE + "2");
    Map<String, ResourceBundle> defaultProperties = prepareDefaultProperties(
            null, KEY3, VALUE + "3");
    List<Locale> locales = prepareLocaleList(null);
    prepareFacesContextStub(Locale.GERMAN, Locale.ENGLISH);
    // when
    Workbook result = ExcelHandler.createExcel(keyList, defaultProperties,
            localizedProperties, null,
            BaseBean.LABEL_USERINTERFACE_TRANSLARIONS, locales);
    // then
    verifyCreatedResult(result, "User interface",
            "Add your language code here");
    assertEquals("", result.getSheetAt(0).getRow(1).getCell(1)
            .getStringCellValue());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:ExcelHandlerTest.java

示例14: createExcel_onlyStandardLanguages

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
@Test
public void createExcel_onlyStandardLanguages() throws Exception {
    // given

    List<String> keyList = new ArrayList<String>();
    keyList.add(KEY1);
    Map<String, ResourceBundle> defaultProperties = prepareDefaultProperties(
            null, KEY1, VALUE + "1");
    List<Locale> locales = prepareLocaleList(null);
    prepareFacesContextStub(Locale.GERMAN, Locale.ENGLISH);
    // when
    Workbook result = ExcelHandler.createExcel(keyList, defaultProperties,
            null, null, BaseBean.LABEL_USERINTERFACE_TRANSLARIONS, locales);
    // then
    verifyCreatedResult(result, "User interface",
            "Add your language code here");
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:ExcelHandlerTest.java

示例15: createExcel_withOneMoreStandardLanguage

import org.apache.poi.ss.usermodel.Workbook; //导入依赖的package包/类
@Test
public void createExcel_withOneMoreStandardLanguage() throws Exception {
    // given

    List<String> keyList = new ArrayList<String>();
    keyList.add(KEY1);
    Map<String, Properties> localizedProperties = prepareProperties(DE,
            KEY1, VALUE + "1");
    Map<String, ResourceBundle> defaultProperties = prepareDefaultProperties(
            null, KEY1, VALUE + "1");
    List<Locale> locales = prepareLocaleList(DE);
    prepareFacesContextStub(Locale.GERMAN, Locale.ENGLISH);
    // when
    Workbook result = ExcelHandler.createExcel(keyList, defaultProperties,
            localizedProperties, null,
            BaseBean.LABEL_USERINTERFACE_TRANSLARIONS, locales);
    // then
    verifyCreatedResult(result, "User interface", DE);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:ExcelHandlerTest.java


注:本文中的org.apache.poi.ss.usermodel.Workbook类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。