We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

在应用里打开某个word文件

如题,我想用该API 打开一个文件可以么?需求就是给一个word文档在应用内打开。

您好!

示例代码如下:

<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>com<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>.<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>aspose<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>.<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>words<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>.<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>Document doc <font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>=<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”> <font color=“RED” style=“font-family: “Courier New”; font-size: small;”>new <span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>com<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>.<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>aspose<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>.<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>words<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>.<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>Document<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>(<span style=“font-family: “Courier New”; font-size: small; color: rgb(51, 51, 51);”>inputPath<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>)<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>;
<font color=“BLUE” style=“font-family: “Courier New”; font-size: small;”>
/**
* 打开文档
* 将源文件转换成HTML文件后使用WEBVIEW打开即可
*
* @param filePath 源文件路径
* @param savePath 生成的HTML文档路径
* @return
*/
public static boolean changeDoc2HtmlModle(String filePath, String savePath)
{
// The export Font feature requires valid Aspose.Words for Android you can get a temporary License from http://www.aspose.com/corporate/purchase/temporary-license.aspx
try
{
File f = new File(savePath);
if (f.isDirectory())
{
System.out.println("Directory is not created");
} else
{
// f.mkdir();
System.out.println("Directory is created");
}

// String myDir = Environment.getExternalStorageDirectory().getPath() + File.separator + "AsposeWords";
// String resourceDir = myDir + File.separator + "Resources";
// ExStart:ExportResourcesUsingHtmlSaveOptions
Document doc = new Document(filePath);
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setCssStyleSheetType(CssStyleSheetType.EXTERNAL);
saveOptions.setExportFontResources(true);
saveOptions.setResourceFolderAlias("http://example.com/resources");
// saveOptions.setResourceFolder(resourceDir);
doc.save(savePath, saveOptions);
// ExEnd:ExportResourcesUsingHtmlSaveOptions
return true;
} catch (Exception e)
{
e.printStackTrace();
}
return false;
}