-
POI高手看过来...10
想在后台利用JAVA写Excel文件以后,对生成的EXCEL文件加个读取密码,可以通过什么方法实现吗?
请各位高手给点提示...
问题补充:
想在后台利用JAVA写Excel文件以后,对生成的EXCEL文件加个读取密码,可以通过什么方法实现吗?
请各位高手给点提示...
----------------2008/11/19添加
看了看各位提供的关于jxl的添加读取密码的方法,十分的感谢.
现在又有一个新的问题,如果抛开POI用JXL实现读写EXCEL的话,JXL可以实现在后台自动调用打印机打印生成的EXCEL文件么?
在下菜鸟级别,请各位不吝赐教...2008年11月18日 10:13
4个答案 按时间排序 按投票排序
-
采纳的答案
http://blog.csdn.net/qiudawei115/archive/2008/09/11/2911881.aspx
//获取原Sheet页的设置 SheetSettings sheetSetting=sheet.getSettings(); //将原sheet页的打印设置设置到当前Sheet页中 sheet=new MjJxlExcelCopyPrintSetting().copySheetSettingToSheet(sheet, sheetSetting); 下面是MjJxlExcelCopyPrintSetting的代码: import jxl.HeaderFooter; import jxl.Range; import jxl.SheetSettings; import jxl.format.PageOrientation; import jxl.format.PaperSize; import jxl.write.WritableSheet; /** * 读取Jxl方法并设置 * @author 邱大为 * @version 1.0 */ public class MjJxlExcelCopyPrintSetting { /** * 该方法将setting设置到sheet中 * @param sheet 需要设置的sheet * @param setting 被设置的属性 * @return */ public WritableSheet copySheetSettingToSheet(WritableSheet sheet,SheetSettings setting){ // 设置原Sheet打印属性到新Sheet页 SheetSettings sheetSettings= sheet.getSettings(); sheetSettings.setAutomaticFormulaCalculation(setting.getAutomaticFormulaCalculation()); sheetSettings.setBottomMargin(setting.getBottomMargin()); sheetSettings.setCopies(setting.getCopies()); sheetSettings.setDefaultColumnWidth(setting.getDefaultColumnWidth()); sheetSettings.setDefaultRowHeight(setting.getDefaultRowHeight()); sheetSettings.setDisplayZeroValues(setting.getDisplayZeroValues()); sheetSettings.setFitHeight(setting.getFitHeight()); sheetSettings.setFitToPages(setting.getFitToPages()); sheetSettings.setFitWidth(setting.getFitWidth()); HeaderFooter footer=setting.getFooter(); if(footer!=null){ sheetSettings.setFooter(footer); } sheetSettings.setFooterMargin(setting.getFooterMargin()); HeaderFooter header=setting.getHeader(); if(header!=null){ sheetSettings.setHeader(header); } sheetSettings.setHeaderMargin(setting.getHeaderMargin()); sheetSettings.setHidden(setting.isHidden()); sheetSettings.setHorizontalCentre(setting.isHorizontalCentre()); sheetSettings.setHorizontalFreeze(setting.getHorizontalFreeze()); sheetSettings.setHorizontalPrintResolution(setting.getHorizontalPrintResolution()); sheetSettings.setLeftMargin(setting.getLeftMargin()); sheetSettings.setNormalMagnification(setting.getNormalMagnification()); PageOrientation pageOrientation=setting.getOrientation(); if(pageOrientation!=null){ sheetSettings.setOrientation(pageOrientation); } sheetSettings.setPageBreakPreviewMagnification(setting.getPageBreakPreviewMagnification()); sheetSettings.setPageBreakPreviewMode(setting.getPageBreakPreviewMode()); sheetSettings.setPageStart(setting.getPageStart()); PaperSize paperSize=setting.getPaperSize(); if(paperSize!=null){ sheetSettings.setPaperSize(setting.getPaperSize()); } sheetSettings.setPassword(setting.getPassword()); sheetSettings.setPasswordHash(setting.getPasswordHash()); Range printArea=setting.getPrintArea(); if(printArea!=null){ sheetSettings.setPrintArea(printArea.getTopLeft()==null?0:printArea.getTopLeft().getColumn(), printArea.getTopLeft()==null?0:printArea.getTopLeft().getRow(), printArea.getBottomRight()==null?0:printArea.getBottomRight().getColumn(), printArea.getBottomRight()==null?0:printArea.getBottomRight().getRow()); } sheetSettings.setPrintGridLines(setting.getPrintGridLines()); sheetSettings.setPrintHeaders(setting.getPrintHeaders()); Range printTitlesCol=setting.getPrintTitlesCol(); if(printTitlesCol!=null){ sheetSettings.setPrintTitlesCol(printTitlesCol.getTopLeft()==null?0:printTitlesCol.getTopLeft().getColumn(), printTitlesCol.getBottomRight()==null?0:printTitlesCol.getBottomRight().getColumn()); } Range printTitlesRow=setting.getPrintTitlesRow(); if(printTitlesRow!=null){ sheetSettings.setPrintTitlesRow(printTitlesRow.getTopLeft()==null?0:printTitlesRow.getTopLeft().getRow(), printTitlesRow.getBottomRight()==null?0:printTitlesRow.getBottomRight().getRow()); } sheetSettings.setProtected(setting.isProtected()); sheetSettings.setRecalculateFormulasBeforeSave(setting.getRecalculateFormulasBeforeSave()); sheetSettings.setRightMargin(setting.getRightMargin()); sheetSettings.setScaleFactor(setting.getScaleFactor()); sheetSettings.setSelected(setting.isSelected()); sheetSettings.setShowGridLines(setting.getShowGridLines()); sheetSettings.setTopMargin(setting.getTopMargin()); sheetSettings.setVerticalCentre(setting.isVerticalCentre()); sheetSettings.setVerticalFreeze(setting.getVerticalFreeze()); sheetSettings.setVerticalPrintResolution(setting.getVerticalPrintResolution()); sheetSettings.setZoomFactor(setting.getZoomFactor()); return sheet; } } 关于POI的打印设置: 转自http://bbs.club.sina.com.cn/tableforum/App/view.php?bbsid=343&subid=0&fid=5477&tbid=8182特此感谢 1.页面 1.1方向 1.1.1纵向(T)HSSFPrintSetup#setLandscape(false); [默认状态] 1.1.2横向(L)HSSFPrintSetup#setLandscape(true); 1.2缩放 1.2.1缩放比例(A)HSSFPrintSetup#setScale((short) 100);[默认状态] 1.2.2调整(F) 页宽 HSSFPrintSetup#setFitWidth((short) 1); 页高 HSSFPrintSetup#setFitHeight((short) 0); 1.3纸张大小(Z)HSSFPrintSetup#setPageSize(HSSFPrintSetup.LETTER_PAPERSIZE); 纸张大小的定义说明: public static final short LETTER_PAPERSIZE = 1; public static final short LEGAL_PAPERSIZE = 5; public static final short EXECUTIVE_PAPERSIZE = 7; public static final short A4_PAPERSIZE = 9; public static final short A5_PAPERSIZE = 11; public static final short ENVELOPE_10_PAPERSIZE = 20; public static final short ENVELOPE_DL_PAPERSIZE = 27; public static final short ENVELOPE_CS_PAPERSIZE = 28; public static final short ENVELOPE_MONARCH_PAPERSIZE = 37; 1.4打印质量(Q)HSSFPrintSetup#setVResolution((short) 300) 1.5起始页码(R)HSSFPrintSetup#setPageStrart((short) 0);[默认状态] 2页面距 2.1上(T)HSSFSheet#setMargin(HSSFSheet.TopMargin,(short)0.6); 2.2下(B)HSSFSheet#setMargin(HSSFSheet.BottomMargin,(short)0.6); 2.3左(L)HSSFSheet#setMargin(HSSFSheet.LeftMargin,(short)0.6); 2.4右(R)HSSFSheet#setMargin(HSSFSheet.RightMargin,(short)0.2); 2.5页眉(A)HSSFPrintSetup#setHeaderMargin((double)0.2); 2.6页脚(F)HSSFPrintSetup#setFooterMargin((double)0.6); 2.7居中方式 2.7.1水平(Z)HSSFSheet#setHorizontallyCenter(false); 2.7.2垂直(V)HSSFSheet#setVerticallyCenter(false); 3页眉/页脚 3.1页眉HSSFHeader#setLeft(HSSFHeader.date(); 说明: 首先获得HSSFHeader对象 确定页眉的显示位置(如,左边显示页眉HSSFHeader#setLeft(显示内容)) 可使用HSSFHeader#setLeft,setCenter,setRight 3.2页脚HSSFFotter#setLeft(HSSFFotter.page()+”/”+HSSFFotter.numPages()); 说明同3.1 首先获得HSSFFotter对象 确定页眉的显示位置(如,左边显示页眉HSSFFotter#setLeft(显示内容)) 可使用HSSFFotter#setLeft,setCenter,setRight 4工作表 4.1打印区域 HSSFWorkbook#setPrintArea(intsheetIndex, intstartColumn, intendColumn, intstartRow, intendRow); 参数的说明 sheetIndex–从0开始的sheet的索引编号 startColumn-打印区域的开始列号 endColumn-打印区域的结束列号 startRow-打印区域的开始行号 endRow-打印区域的结束行号 4.2打印标题 HSSFWorkbook#setRepeatingRowsAndColumns(intsheetIndex, intstartColumn, intendColumn, intstartRow, intendRow); 参数说明同4.1 使用说明: 仅仅设置左端标题列: workbook.setRepeatingRowsAndColumns(0,0,1,-1-1); 仅仅设置顶端标题行: workbook.setRepeatingRowsAndColumns(0,-1,-1,0,4); 同时设置左端和顶端标题: workbook.setRepeatingRowsAndColumns(0,-1,-1,-1,-1); 4.3打印 网格线(G):HSSFSheet#setPrintGridlines(false); 单色打印(B)HSSFPrintSetup#setNoColor(false); 按草稿方式(Q):HSSFPrintSetup#setDraft(false); 行号列标(L):(很抱歉,还没有找到) 批注(M):(很抱歉,还没有找到) 错误单元格打印为(E):(很抱歉,还没有找到) 4.4打印顺序 HSSFPrintSetup#setLeftToRight(false);
2008年11月19日 11:51
-
import java.io.File; import java.io.IOException; import jxl.SheetSettings; import jxl.Workbook; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; public class TestPassword { public static void main(String[] args) throws IOException, WriteException { WritableWorkbook wwb = Workbook.createWorkbook(new File("d:/test.xls")); WritableSheet ws = wwb.createSheet("Test Sheet 1", 0); SheetSettings ss = ws.getSettings(); ss.setPassword("12345678"); ss.setProtected(true); wwb.write(); wwb.close(); } }
2008年11月18日 11:13
相关推荐
poi4.1.6 org.apache.poi.xwpf.converter.core word转pdf
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFPalette; ...
标题中的"fr.opensagres.poi.xwpf.converter.7z"是一个压缩包文件,其中包含了两个与Apache POI相关的库,这些库主要用于处理WordprocessingML(.docx)文档,并将其转换为PDF格式。Apache POI是Java领域的一个著名...
org.apache.poi.xwpf.converter.pdf-1.0.6 org.apache.poi.xwpf.converter.core-1.0.6 org.apache.poi.xwpf.converter-0.9.1
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFPalette; ...
org.apache.poi.xwpf.converter.pdf-1.0.6.jar 文件 org.apache.poi.xwpf.converter.pdf-1.0.6 org.apache.poi.xwpf.converter.core-1.0.6 org.apache.poi.xwpf.converter-0.9.1
org.apache.poi.xwpf.converter.core-1.0.6org.apache.poi.xwpf.converter.core-1.0.6org.apache.poi.xwpf.converter.core-1.0.6org.apache.poi.xwpf.converter.core-1.0.6
在给定的标题"org.apache.poi.xwpf.converter.pdf-1.0.6.jar"中,提到的是Apache POI的一个特定模块——XWPF(XML Word Processing Format),其主要关注于处理Word文档的XDOCReport库的PDF转换功能。描述中指出,这...
标题中的"org.apache.poi.xwpf.converter"指的是这个特定的转换库,它包含了处理XML Word Processor Format (XWPF) 文件所需的类和方法。XWPF是Apache POI用来解析和生成DOCX文件的内部表示。这个库允许开发者编程...
解决POI读取EXCEL时报org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException异常
"org.apache.poi.xwpf.converter.core-1.0.4.jar"是Apache POI的一个扩展库,主要用于XWPF(XML Word Processing Format)文档的转换,特别是针对Word 2007及以上版本的.openXML标准文档。 此扩展包包含了三个关键...
org.apache.poi.xwpf.converter-0.9.0 org.apache.poi.xwpf.converter.xhtml-1.0.2 org.apache.poi.xwpf.converter-0.9.0 poi-3.10-FINAL-20140208 等
org.apache.poi.xwpf.converter.core-1.0.2.jar 之前找的都要分,来个不要分的,只能找到1.0.2以下的
org.apache.poi.xwpf.converter.core-1.0.6.jar
velocity开发插件org.apache.poi.hssf.usermodel.HSSFCellorg.apache.poi.hssf.usermodel.HSSFCell
org.apache.poi JAR包,解决import org.apache.poi.hssf.usermodel.HSSFWorkbook; 支持office全系excel文件解析。 import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; ...
注:下文中的 *** 代表文件名中的版本号。 # 【poi-***.jar中文文档.zip】 中包含: 中文文档:【poi-***-javadoc-...org.apache.poi.EncryptedDocumentException org.apache.poi.OldFileFormatException ...... ```
这个特定的资源,"org.apache.poi.xwpf.converter-0.9.8.jar",是Apache POI项目的一个组件,专注于XWPF(XML Word Processing Format)转换器,版本为0.9.8。这个库的主要功能是将XWPF文档转换成其他格式,例如HTML...
注:下文中的 *** 代表文件名中的版本号。 # 【poi-***.jar中文文档.zip】 中包含: 中文文档:【poi-***-javadoc-...org.apache.poi.EncryptedDocumentException org.apache.poi.OldFileFormatException ...... ```