On converting the attached excel document to HTML, the hyperlink ‘Refer a range’ does not work.
For reference, here’s the sample code.
private static void excelDocumentToHTML() throws Exception{
Workbook workbook = new Workbook(“d:\temp\Copy of CellReferHyperlink.xlsx”);
com.aspose.cells.HtmlSaveOptions htmlSaveOptions = new com.aspose.cells.HtmlSaveOptions(com.aspose.cells.SaveFormat.HTML);
File tempAttachmentsDir = new File(“d:\temp\123”);
try {
File htmlFile = new File(tempAttachmentsDir.getAbsolutePath(), “index.html”);
htmlSaveOptions.setAttachedFilesDirectory(tempAttachmentsDir.getAbsolutePath());
workbook.save(htmlFile.getAbsolutePath(), htmlSaveOptions);
File zipFile = File.createTempFile(“Prefix”, “.zip”);
createZipFile(tempAttachmentsDir.listFiles(), zipFile);
System.out.println(zipFile.getAbsolutePath());
} finally {
}
}
private static void createZipFile(File[] inputfiles, File zipFile) throws FileNotFoundException, IOException {
FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
try {
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
try {
for (int i = 0; inputfiles != null && i < inputfiles.length; i++) {
addFileToZip(inputfiles[i], zipOutputStream, null);
}
} finally {
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} finally {
fileOutputStream.close();
}
}
private static void addFileToZip(File file, ZipOutputStream zipOutputStream, String folderHeirarchy) throws IOException {
if (file.isFile()) {
byte[] buf = new byte[1024];
FileInputStream in = new FileInputStream(file);
try {
String originalFileName = file.getName();
String targetFileName = null;
if (folderHeirarchy != null && !folderHeirarchy.isEmpty()) {
targetFileName = folderHeirarchy + “/” + originalFileName;
} else {
targetFileName = originalFileName;
}
// Add ZIP entry to output stream.
zipOutputStream.putNextEntry(new ZipEntry(targetFileName));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
zipOutputStream.write(buf, 0, len);
}
} finally {
// Complete the entry
zipOutputStream.closeEntry();
in.close();
}
} else {
File[] childFiles = file.listFiles();
for (int j = 0; childFiles != null && j < childFiles.length; j++) {
if (folderHeirarchy != null && !folderHeirarchy.isEmpty()) {
addFileToZip(childFiles[j], zipOutputStream, folderHeirarchy + “/” + file.getName());
} else {
addFileToZip(childFiles[j], zipOutputStream, file.getName());
}
}
}
}
I have verified using MS Excel that hyperlink works on saving this excel doc as Web Page but via Aspose I am unable to achieve this.
Could you please help on this.