excel ppt转换html.docx

上传人:b****6 文档编号:6004319 上传时间:2023-01-02 格式:DOCX 页数:14 大小:17.95KB
下载 相关 举报
excel ppt转换html.docx_第1页
第1页 / 共14页
excel ppt转换html.docx_第2页
第2页 / 共14页
excel ppt转换html.docx_第3页
第3页 / 共14页
excel ppt转换html.docx_第4页
第4页 / 共14页
excel ppt转换html.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

excel ppt转换html.docx

《excel ppt转换html.docx》由会员分享,可在线阅读,更多相关《excel ppt转换html.docx(14页珍藏版)》请在冰豆网上搜索。

excel ppt转换html.docx

excelppt转换html

packagecom.gssoftwares.rcsa;

importjava.util.ArrayList;

importjava.util.List;

importcom.jacob.activeX.ActiveXComponent;

import.ComThread;

import.Dispatch;

import.Variant;

publicclassMSExcelManager{

publicstaticfinalintEXCEL_HTML=44;

privatestaticActiveXComponentxl=null;//Excel对象(防止打开多个)

privatestaticDispatchworkbooks=null;//工作簿对象

privateDispatchworkbook=null;//具体工作簿

privateDispatchsheets=null;//获得sheets集合对象

privateDispatchcurrentSheet=null;//当前sheet

publicbooleanPPttoHtml(Strings,Strings1){

ComThread.InitSTA();

ActiveXComponentactivexcomponent=newActiveXComponent("PowerPoint.Application");

Strings2=s;

Strings3=s1;

booleanflag=false;

try{

Dispatchdispatch=activexcomponent.getProperty("Presentations").toDispatch();

Dispatchdispatch1=Dispatch.call(dispatch,"Open",s2,newVariant(-1),newVariant(-1),newVariant(0)).toDispatch();

Dispatch.call(dispatch1,"SaveAs",s3,newVariant(12));

Variantvariant=newVariant(-1);

Dispatch.call(dispatch1,"Close");

flag=true;

}catch(Exceptionexception){

System.out.println("|||"+exception.toString());

}finally{

activexcomponent.invoke("Quit",newVariant[0]);

ComThread.Release();

ComThread.quitMainSTA();

}

returnflag;

}

publicbooleanExceltoHtml(Strings,Strings1){

ComThread.InitSTA();

ActiveXComponentactivexcomponent=newActiveXComponent("Excel.Application");

Strings2=s;

Strings3=s1;

booleanflag=false;

try{

activexcomponent.setProperty("Visible",newVariant(false));

Dispatchdispatch=activexcomponent.getProperty("Workbooks").toDispatch();

Dispatchdispatch1=Dispatch.invoke(dispatch,"Open",1,

newObject[]{s2,newVariant(false),newVariant(true)},newint[1]).toDispatch();

Dispatch.call(dispatch1,"SaveAs",s3,newVariant(44));

Variantvariant=newVariant(false);

Dispatch.call(dispatch1,"Close",variant);

flag=true;

}catch(Exceptionexception){

System.out.println("|||"+exception.toString());

}finally{

activexcomponent.invoke("Quit",newVariant[0]);

ComThread.Release();

ComThread.quitMainSTA();

}

returnflag;

}

/**

*打开excel文件

*@paramfilepath

*文件路径名称

*@paramvisible

*是否显示打开

*@paramreadonly

*是否只读方式打开

*/

privatevoidOpenExcel(Stringfilepath,booleanvisible){

try{

initComponents();//清空原始变量

ComThread.InitSTA();

if(xl==null)

xl=newActiveXComponent("Excel.Application");//Excel对象

xl.setProperty("Visible",newVariant(visible));//设置是否显示打开excel

if(workbooks==null)

workbooks=xl.getProperty("Workbooks").toDispatch();//打开具体工作簿

workbook=Dispatch.invoke(workbooks,"Open",Dispatch.Method,newObject[]{filepath,newVariant(false),//是否以只读方式打开

newVariant(true),"1","pwd"},//输入密码"pwd",若有密码则进行匹配,无则直接打开

newint[1]).toDispatch();

}catch(Exceptione){

e.printStackTrace();

releaseSource();

}

}

/**

*工作簿另存为

*@paramfilePath

*另存为的路径例如SaveAs="D:

TEST/c.xlsx"

*/

privatevoidSaveAs(StringfilePath){

Dispatch.call(workbook,"SaveAs",filePath);

}

/**

*关闭excel文档

*@paramf

*含义不明(关闭是否保存?

默认false)

*/

privatevoidCloseExcel(booleanf){

try{

Dispatch.call(workbook,"Save");

Dispatch.call(workbook,"Close",newVariant(f));

}catch(Exceptione){

e.printStackTrace();

}finally{

releaseSource();

}

}

/*

*初始化

*/

privatevoidinitComponents(){

workbook=null;

currentSheet=null;

sheets=null;

}

/**

*释放资源

*/

privatestaticvoidreleaseSource(){

if(xl!

=null){

xl.invoke("Quit",newVariant[]{});

xl=null;

}

workbooks=null;

ComThread.Release();

System.gc();

}

/**

*得到当前sheet

*@return

*/

privateDispatchgetCurrentSheet(){

currentSheet=Dispatch.get(workbook,"ActiveSheet").toDispatch();

returncurrentSheet;

}

/**

*修改当前工作表的名字

*@paramnewName

*/

privatevoidmodifyCurrentSheetName(StringnewName){

Dispatch.put(getCurrentSheet(),"name",newName);

}

/**

*得到当前工作表的名字

*@return

*/

privateStringgetCurrentSheetName(Dispatchsheets){

returnDispatch.get(sheets,"name").toString();

}

/**

*通过工作表名字得到工作表

*@paramname

*sheetName

*@return

*/

privateDispatchgetSheetByName(Stringname){

returnDispatch.invoke(getSheets(),"Item",Dispatch.Get,newObject[]{name},newint[1]).toDispatch();

}

/**

*得到sheets的集合对象

*@return

*/

privateDispatchgetSheets(){

if(sheets==null)

sheets=Dispatch.get(workbook,"sheets").toDispatch();

returnsheets;

}

/**

*通过工作表索引得到工作表(第一个工作簿index为1)

*@paramindex

*@returnsheet对象

*/

privateDispatchgetSheetByIndex(Integerindex){

returnDispatch.invoke(getSheets(),"Item",Dispatch.Get,newObject[]{index},newint[1]).toDispatch();

}

/**

*得到sheet的总数

*@return

*/

privateintgetSheetCount(){

intcount=Dispatch.get(getSheets(),"count").toInt();

returncount;

}

/**

*给所有的sheet添加背景

*@paramfilepath

*图片路径

*/

publicvoidsetBlackGroudPrituce(Stringfilepath){

intnum=this.getSheetCount();

for(inti=1;i<=num;i++){

Dispatchsheets=this.getSheetByIndex(i);

Dispatch.call(sheets,"SetBackgroundPicture",filepath);

}

}

/**

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

*/

publicvoidaddSheet(Stringname){

//for(inti=1;i<=this.getSheetCount();i++){

//Dispatchsheets=this.getSheetByIndex(i);

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

//{

//returnfalse;

//}

//}

currentSheet=Dispatch.get(Dispatch.get(workbook,"sheets").toDispatch(),"add").toDispatch();

//Dispatch.put(currentSheet,"Name",name);

Dispatch.put(currentSheet,"Visible",newBoolean(false));

System.out.println("插入信息为:

"+name);

}

/**

*得到工作薄的名字

*@return

*/

privateStringgetWorkbookName(){

if(workbook==null)

returnnull;

returnDispatch.get(workbook,"name").toString();

}

/**

*获取所有表名

*/

publicListfindSheetName(){

intnum=this.getSheetCount();

Listlist=newArrayList();

for(inti=1;i<=num;i++){

currentSheet=this.getSheetByIndex(i);

list.add(this.getCurrentSheetName(currentSheet));

}

returnlist;

}

/**

*设置页脚信息

*/

privatevoidsetFooter(Stringfoot){

currentSheet=this.getCurrentSheet();

DispatchPageSetup=Dispatch.get(currentSheet,"PageSetup").toDispatch();

Dispatch.put(PageSetup,"CenterFooter",foot);

}

/**

*获取页脚信息

*/

privateStringgetFooter(){

currentSheet=this.getCurrentSheet();

DispatchPageSetup=Dispatch.get(currentSheet,"PageSetup").toDispatch();

returnDispatch.get(PageSetup,"CenterFooter").toString();

}

/**

*锁定工作簿

*/

privatevoidsetPassword(){

Dispatch.call(workbook,"Protect",123,true,false);

}

/**

*设置名称管理器

*

*@paramname

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

*@paramcomment

*备注

*@paramplace

*备注位置

*@return

*/

publicvoidsetName(Stringname,Stringplace,Stringcomment){

DispatchNames=Dispatch.get(workbook,"Names").toDispatch();

Dispatch.call(Names,"Add",name,place,false).toDispatch();

Dispatch.put(Names,"Comment",comment);//插入备注

}

/**

*获取名称管理器

*@paramname

*名称管理器名

*@return

*/

publicStringgetName(Stringname){

DispatchNames=Dispatch.get(workbook,"Names").toDispatch();

DispatchName=Dispatch.call(Names,"Item",name).toDispatch();

returnDispatch.get(Name,"Value").toString();

}

/**

*单元格写入值

*@paramsheet

*被操作的sheet

*@paramposition

*单元格位置,如:

C1

*@paramtype

*值的属性如:

value

*@paramvalue

*/

privatevoidsetValue(Stringposition,Objectvalue){

currentSheet=this.getCurrentSheet();

Dispatchcell=Dispatch.invoke(currentSheet,"Range",Dispatch.Get,newObject[]{position},newint[1])

.toDispatch();

Dispatch.put(cell,"Value",value);

Stringcolor=this.getColor(cell);

this.setFont(cell,color);

}

/**

*设置字体

*/

privatevoidsetFont(Dispatchcell,Stringcolor){

Dispatchfont=Dispatch.get(cell,"Font").toDispatch();

//Dispatch.put(font,"FontStyle","BoldItalic");

Dispatch.put(font,"size","1");

Dispatch.put(font,"color",color);

}

/**

*获取背景颜色

*/

privateStringgetColor(Dispatchcell){

DispatchInterior=Dispatch.get(cell,"Interior").toDispatch();

Stringcolor=Dispatch.get(Interior,"color").toString();

returncolor;

}

/**

*单元格读取值

*@paramposition

*单元格位置,如:

C1

*@paramsheet

*@return

*/

privateVariantgetValue(Stringposition){

currentSheet=this.getCurrentSheet();

Dispatchcell=Dispatch.invoke(currentSheet,"Range",Dispatch.Get,newObject[]{position},newint[1])

.toDispatch();

Variantvalue=Dispatch.get(cell,"Value");

returnvalue;

}

/**

*获取最大行数

*@return

*/

privateintgetRowCount(){

currentSheet=this.getCurrentSheet();

DispatchUsedRange=Dispatch.get(currentSheet,"UsedRange").toDispatch();

Dispatchrows=Dispatch.get(UsedRange,"Rows").toDispatch();

intnum=Dispatch.get(rows,"count").getInt();

returnnum;

}

/**

*获取最大列数

*@return

*/

privateintgetColumnCount(){

currentSheet=this.getCurrentSheet();

DispatchUsedRange=Dispatch.get(currentSheet,"UsedRange").toDispatch();

DispatchColumns=Dispatch.get(UsedRange,"Columns").toDispatch();

intnum=Dispatch.get(Columns,"count").getInt();

returnnum;

}

/**

*获取位置

*@paramrnum

*最大行数

*@paramcnum

*最大列数

*/

privateStringgetCellPosition(intrnum,intcnum){

Stringcposition="";

if(cnum>26){

intmultiple=(cnum)/26;

intremainder=(cnum)%26;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 表格类模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1