jocad 在linux 中的使用?
发布网友
发布时间:2022-06-19 13:43
我来回答
共5个回答
热心网友
时间:2024-11-29 12:47
/// <summary>
/// 将PPT文件转换成HTML格式
/// </summary>
/// <param name="PptFilePath">PPT文件路径</param>
public static void PptToHtmlFile(string PptFilePath)
{
Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Interop.PowerPoint.Presentation pptFile = null;
try
{
//获得html文件名
string htmlFileName = PptFilePath.Substring(0, PptFilePath.LastIndexOf(".")) + ".html";
//打开一个ppt文件
pptFile = ppt.Presentations.Open(PptFilePath, Microsoft.Office.Core.MsoTriState.msoTrue,
Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
//转换成html格式
pptFile.SaveAs(htmlFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML,
Microsoft.Office.Core.MsoTriState.msoCTrue);
}
finally
{
if (pptFile != null)
{
pptFile.Close();
}
ppt.Quit();
GC.Collect();
}
}
/// <summary>
/// 将Excel文件转换成HTML格式
/// </summary>
/// <param name="ExcelFilePath">Excel文件路径</param>
public static void ExcelToHtmlFile(string ExcelFilePath)
{
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook oBook = null;
// 缺省参数
object Unknown = Type.Missing;
try
{
//目标html文件路径
object Target = ExcelFilePath.Substring(0, ExcelFilePath.LastIndexOf(".")) + ".html";
//为了保险,只读方式打开
object readOnly = true;
// 指定另存为格式(html)
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
//打开Excel文件
oBook = excelApp.Workbooks.Open(ExcelFilePath, Unknown, readOnly,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown);
// 转换格式
oBook.SaveAs(Target, format, Unknown, Unknown, Unknown, Unknown,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Unknown, Unknown, Unknown, Unknown, Unknown);
}
finally
{
if (oBook != null)
{
oBook.Close(false, Unknown, Unknown);
}
excelApp.Quit();
GC.Collect();
}
}
/// <summary>
/// 将Word文档转换成HTML格式
/// </summary>
/// <param name="WordFilePath">Word文档格式</param>
public static void WordToHtmlFile(string WordFilePath)
{
Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = null;
// 缺省参数
object Unknown = Type.Missing;
try
{
// 指定原文件和目标文件
object Source = WordFilePath;
object Target = WordFilePath.Substring(0, WordFilePath.LastIndexOf(".")) + ".html";
//为了保险,只读方式打开
object readOnly = true;
// 指定另存为格式(html)
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
// 打开doc文件
doc = newApp.Documents.Open(ref Source, ref Unknown, ref readOnly,
//------------
热心网友
时间:2024-11-29 12:47
linux 下也是支持jocad的
如:
使用jacob调用word文件中的宏的代码。
首先说明一下,由于jacob是java与com之间的bridge,所以先描述一下使用vb调用上面的MyWordMacro宏的代码,这样可以与java代码作比较,更利于理解jacob的工作方式:
Sub AutomateWord_OpenDoc()
Dim wrdApp As Object
Dim wrdDoc As Object
Dim strFileName As String
Set wrdApp = CreateObject("Word.Application")
On Error GoTo DocError
'包含marco的word文件
strFileName = "c:\MacroTest.doc"
'打开文件
Set wrdDoc = wrdApp.Documents.Open(strFileName)
'运行宏
wrdDoc.MyWordMacro ("This is a test.")DocError:
If Err.Number <> 0 Then MsgBox Err.Description
'退出word
wrdApp.Quit
'清除内存
Set wrdApp = Nothing
Set wrdDoc = NothingEnd SubPrivate Sub Command1_Click()
AutomateWord_OpenDocEnd Sub
而对应的java代码如下:
package com.bjinfotech.practice.jacob;import com.jacob.com.*;import com.jacob.activeX.*;/** * 调用word文件中的宏 * @author 聪明的猪 * */public class Dispatch_MSWordMacro {
/**
* 打开word,调用word中的宏
* @param filePath word文件路径
* @param macroName 被调用的宏名字
* @param parameter 调用宏的参数数组
*/
public void callWordMacro(String filePath,String macroName,Object parameter[]){
//建立ActiveX部件
ActiveXComponent wrdCom=new ActiveXComponent("Word.Application");
try{
//返回wrdCom.Documents的Dispatch
Object wrdDocs=wrdCom.getProperty("Documents").toDispatch();
//调用wrdCom.Documents.Open方法打开指定的word文档,返回wordDoc
Object wrdDoc=Dispatch.invoke(wrdDocs,"Open",Dispatch.Method,new Object[]{filePath},new int[1]).toDispatch();
//使用方法传入的参数parameter调用word文档中的MyWordMacro宏//
Dispatch.call(wrdDoc,macroName,parameter);
Dispatch.invoke(wrdDoc,macroName,Dispatch.Method,parameter,new int[1]);
}
catch(Exception ex){
ex.printStackTrace();
}
finally{
//关闭word文件
wrdCom.invoke("Quit",new Variant[]{});
}
}
public static void main(String[] argv){
Dispatch_MSWordMacro d=new Dispatch_MSWordMacro();
d.callWordMacro("E:/eclipse3.1RC3/workspace/jacobPractice/src/com/bjinfotech/practice/jacob/MacroTest.doc","MyWordMacro",new String[]{"这是测试信息"});
}}
热心网友
时间:2024-11-29 12:48
可以采用poi
http://poi.apache.org/
最近就做过这样的项目。
从xsl中获取数据。使用poi解析excel文件
热心网友
时间:2024-11-29 12:49
poi http://poi.apache.org/
http://blog.tostudy.com.cn/blog/show_995.html
参考资料:http://blog.tostudy.com.cn/blog/show_995.html
热心网友
时间:2024-11-29 12:49
从xsl中获取数据。使用poi解析excel文件