请帮助我使用Java中的Aspose word报告在Document中创建Hyperlink With
答案 0 :(得分:2)
您可以使用以下任何Aspose.Words for Java代码来满足此要求:
方法#1:
"use strict";
var webdriver = require('selenium-webdriver'); // muse use selenium-webdriver version <=2.47.0
var username = "my_username";
var accessKey = "my_access_key";
var driver;
var deviceTypes = {
desktop: 'desktop',
mobile: 'mobile'
}
/*Desktops*/
var screenResolutions = {
desktop: "1280x1024",
tablet: "1024x768",
mobile: "800x600"
};
var browsers = [
/*Desktop*/
{
type: deviceTypes.desktop,
browser: 'chrome',
platform: 'Windows XP',
version: '43.0',
screenResolution: screenResolutions.desktop
},
{
type: deviceTypes.desktop,
browser: 'firefox',
platform: 'Windows XP',
version: '38.0',
screenResolution: screenResolutions.desktop
},
{
type: deviceTypes.desktop,
browser: 'internet explorer',
platform: 'Windows 10',
version: '11.103',
screenResolution: screenResolutions.desktop
},
{
type: deviceTypes.desktop,
browser: 'safari',
platform: 'OS X 10.8',
version: '6.0',
screenResolution: screenResolutions.desktop
},
/*Tablet*/
{
type: deviceTypes.desktop,
browser: 'chrome',
platform: 'Windows XP',
version: '43.0',
screenResolution: screenResolutions.tablet
},
{
type: deviceTypes.desktop,
browser: 'firefox',
platform: 'Windows XP',
version: '38.0',
screenResolution: screenResolutions.tablet
},
{
type: deviceTypes.desktop,
browser: 'internet explorer',
platform: 'Windows 10',
version: '11.103',
screenResolution: screenResolutions.tablet
},
{
type: deviceTypes.desktop,
browser: 'safari',
platform: 'OS X 10.8',
version: '6.0',
screenResolution: screenResolutions.tablet
},
/*Mobiles - Android*/
{
type: deviceTypes.mobile,
browserName: 'android',
platform: 'linux',
version: '5.1',
deviceName: 'Android Emulator',
deviceOrientation: 'portrait'
},
{
type: deviceTypes.mobile,
browserName: 'android',
platform: 'linux',
version: '4.4',
deviceName: 'Samsung Galaxy S4 Emulator',
deviceOrientation: 'portrait'
},
{
type: deviceTypes.mobile,
browserName: 'iphone',
platform: 'OS X 10.10',
version: '9.2',
deviceName: 'iPhone 5s',
deviceOrientation: 'portrait'
}
];
var index = 0;
loopBrowsers();
function loopBrowsers(){
var browserConfig = browsers[index];
var capabilities;
if(browserConfig.type === deviceTypes.desktop){
capabilities = {
'browserName': browserConfig.browser,
'platform': browserConfig.platform,
'version': browserConfig.version,
'screenResolution': browserConfig.screenResolution,
'username': username,
'accessKey': accessKey
}
} else if (browserConfig.type === deviceTypes.mobile) {
capabilities = {
'browserName': browserConfig.browserName,
'platform': browserConfig.platform,
'version': browserConfig.version,
'deviceName': browserConfig.deviceName,
'deviceOrientation': browserConfig.deviceOrientation,
'username': username,
'accessKey': accessKey
}
}
driver = new webdriver.Builder().
withCapabilities(capabilities).
usingServer("http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub").
build();
driver.get('http://example.com');
//Taking screenshot on currently targeting browser
driver.takeScreenshot().then(
function(image, err){
var fileName;
if(browserConfig.type === deviceTypes.desktop){
fileName = "screen_"+browserConfig.browser+"_"+browserConfig.screenResolution;
} else if (browserConfig.type === deviceTypes.mobile) {
fileName = "screen_"+browserConfig.deviceName+"_"+browserConfig.deviceOrientation;
}
require('fs').writeFile("screenshots/"+ fileName +".png", image, 'base64', function(err){
console.log("Completed screenshot: " + index + " any errors: " + err);
index++;
if(index < browsers.length){
loopBrowsers();
} else {
}
});
}
);
driver.quit();
}
方法#2:
Document doc = new Document(getMyDir() + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHyperlink("Aspose", "http://www.aspose.com/", false);
doc.save(getMyDir() + "awjava-16.4.0.docx");
我与Aspose一起担任开发者布道者。