Jacob操作office文档(2)

2019-01-26 14:42

private int getSheetCount() {

int count = Dispatch.get(getSheets(), \ return count; } /**

* 给所有的sheet添加背景 * @param filepath 图片路径 */

public void setBlackGroudPrituce(String filepath) {

int num=this.getSheetCount(); for (int i = 1; i <= num; i++) {

Dispatch sheets=this.getSheetByIndex(i);

Dispatch.call(sheets,\ } } /**

* 添加新的工作表(sheet),并且隐藏(添加后为默认为当前激活的工作表) */

public void addSheet(String name) {

// for (int i = 1; i <= this.getSheetCount(); i++) { // Dispatch sheets=this.getSheetByIndex(i);

// if(name.equals(this.getCurrentSheetName(sheets))) // {

// return false; // } // }

currentSheet=Dispatch.get(Dispatch.get(workbook, \\

// Dispatch.put(currentSheet,\

Dispatch.put(currentSheet, \ System.out.println(\插入信息为:\ } /**

* 得到工作薄的名字 * @return */

private String getWorkbookName() { if(workbook==null) return null;

return Dispatch.get(workbook, \ } /**

* 获取所有表名

*/

public List findSheetName() {

int num=this.getSheetCount(); List list=new ArrayList(); for (int i = 1; i <= num; i++) {

currentSheet=this.getSheetByIndex(i);

list.add(this.getCurrentSheetName(currentSheet)); } return list; } /**

* 设置页脚信息 */

private void setFooter(String foot) {

currentSheet=this.getCurrentSheet();

Dispatch PageSetup=Dispatch.get(currentSheet,\ Dispatch.put(PageSetup,\ } /**

* 获取页脚信息 */

private String getFooter() {

currentSheet=this.getCurrentSheet();

Dispatch PageSetup=Dispatch.get(currentSheet,\ return Dispatch.get(PageSetup,\ } /**

* 锁定工作簿 */

private void setPassword() {

Dispatch.call(workbook, \ } /**

* 设置名称管理器

* @param name 名称管理器名 不能以数字或者下划线开头,中间不能包含空格和其他无效字符

* @param comment 备注 * @param place 备注位置 * @return */

public void setName(String name,String place,String comment) {

Dispatch Names=Dispatch.get(workbook, \ Dispatch.call(Names,\

Dispatch.put(Names, \插入备注 } /**

* 获取名称管理器

* @param name 名称管理器名 * @return */

public String getName(String name) {

Dispatch Names=Dispatch.get(workbook, \ Dispatch Name=Dispatch.call(Names,\ return Dispatch.get(Name, \ } /**

* 单元格写入值

* @param sheet 被操作的sheet

* @param position 单元格位置,如:C1 * @param type 值的属性 如:value * @param value */

private void setValue(String position, Object value) { currentSheet=this.getCurrentSheet();

Dispatch cell = Dispatch.invoke(currentSheet, \

Dispatch.Get, new Object[] { position }, new int[1]) .toDispatch();

Dispatch.put(cell, \ String color=this.getColor(cell); this.setFont(cell,color); } /**

* 设置字体 */

private void setFont(Dispatch cell,String color) {

Dispatch font=Dispatch.get(cell, \ //Dispatch.put(font,\ Dispatch.put(font,\ Dispatch.put(font,\ } /**

* 获取背景颜色 */

private String getColor(Dispatch cell) {

Dispatch Interior=Dispatch.get(cell, \

String color=Dispatch.get(Interior, \ return color; } /**

* 单元格读取值

* @param position 单元格位置,如: C1 * @param sheet * @return */

private Variant getValue(String position) { currentSheet=this.getCurrentSheet();

Dispatch cell = Dispatch.invoke(currentSheet, \ new Object[] { position }, new int[1]).toDispatch(); Variant value = Dispatch.get(cell, \ return value; } /**

* 获取最大行数 * @return */

private int getRowCount() {

currentSheet=this.getCurrentSheet();

Dispatch UsedRange=Dispatch.get(currentSheet, \ Dispatch rows=Dispatch.get(UsedRange, \ int num=Dispatch.get(rows, \ return num; } /**

* 获取最大列数 * @return */

private int getColumnCount() {

currentSheet=this.getCurrentSheet();

Dispatch UsedRange=Dispatch.get(currentSheet, \ Dispatch Columns=Dispatch.get(UsedRange, \ int num=Dispatch.get(Columns, \ return num; } /**

* 获取位置

* @param rnum 最大行数 * @param cnum 最大列数 */

private String getCellPosition(int rnum,int cnum)

{

String cposition=\ if(cnum>26) {

int multiple=(cnum)/26; int remainder=(cnum)&;

char mchar=(char)(multiple+64); char rchar=(char)(remainder+64); cposition=mchar+\ } else {

cposition=(char)(cnum+64)+\ }

cposition+=rnum; return cposition; } /*

* 取消兼容性检查,在保存或者另存为时改检查会导致弹窗 */

private viod setCheckCompatibility(){

Dispatch.put(wookbook, \ }

/*

* 为每个表设置打印区域 */

private void setPrintArea(){

int count = Dispatch.get(sheets, \ for (int i = count; i >= 1; i--) {

sheet = Dispatch.invoke(sheets, \

Dispatch.Get, new Object[] { i }, new int[1]).toDispatch(); Dispatch page = Dispatch.get(sheet, \ Dispatch.put(page, \ Dispatch.put(page, \

Dispatch.put(page, \ //值为100或false Dispatch.put(page, \ //所有行为一页

Dispatch.put(page, \ //所有列为一页(1或false) } } }


Jacob操作office文档(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:上海自贸区的建立对加工贸易企业的影响

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: