Hello,
Hi,
Sample code:
String dynamicRange = “‘Daily Schedule’!B4:C36”;
String worksheetName = “Daily Schedule”;
Workbook workbook = new Workbook(“f:\files\wrong font color\font_color_issue.xlsx”);
Worksheet worksheet = workbook.getWorksheets().get(worksheetName);
// workbook.calculateFormula();
int rangeIndex = workbook.getWorksheets().getNames().add(“dummyrange”);
Name name = workbook.getWorksheets().getNames().get(rangeIndex); name.setRefersTo(dynamicRange );
name = workbook.getWorksheets().getNames().get(rangeIndex);
Range sourceRange = name.getRange();
Workbook newWorkbook = new Workbook(FileFormatType.XLSX);
WorksheetCollection targetWsc = newWorkbook.getWorksheets();
Worksheet targetWs = (Worksheet)targetWsc.get(0);
Range targetRange = targetWs.getCells().createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions options = new PasteOptions();
//Copy column widths
options.setPasteType(PasteType.COLUMN_WIDTHS);
targetRange.copy(sourceRange, options);
// Copy row heights
int rowCount = sourceRange.getRowCount();
int firstRow = sourceRange.getFirstRow();
for (int i = 0; i < rowCount; i++) {
double rowHeight = sourceRange.getWorksheet().getCells().getRowHeight(firstRow++);
targetWs.getCells().setRowHeight(i, rowHeight);
}
//Copy everything else
options.setPasteType(PasteType.ALL);
targetRange.copy(sourceRange, options);
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions(SaveFormat.HTML);
htmlSaveOptions.setHiddenColDisplayType(1);
htmlSaveOptions.setHiddenRowDisplayType(1);
htmlSaveOptions.setParseHtmlTagInCell(true);
newWorkbook.save(“f:\files\out1.html”, htmlSaveOptions);
Worksheet sheetForPDF = newWorkbook.getWorksheets().get(0);
sheetForPDF.getPageSetup().setTopMargin(0);
sheetForPDF.getPageSetup().setBottomMargin(0);
sheetForPDF.getPageSetup().setRightMargin(0);
sheetForPDF.getPageSetup().setLeftMargin(0);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
Worksheet sheetForImage = newWorkbook.getWorksheets().get(0);
sheetForImage.getPageSetup().setTopMargin(0);
sheetForImage.getPageSetup().setBottomMargin(0);
sheetForImage.getPageSetup().setRightMargin(0);
sheetForImage.getPageSetup().setLeftMargin(0);
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.setHorizontalResolution(600);
imageOrPrintOptions.setVerticalResolution(600);
imageOrPrintOptions.setOnePagePerSheet(true);
imageOrPrintOptions.setOnlyArea(true);
imageOrPrintOptions.setImageFormat(ImageFormat.getPng());
SheetRender sr = new SheetRender(sheetForImage, imageOrPrintOptions);
sr.toImage(0, “f:\files\out1.png”);
newWorkbook.save(“f:\files\out1.pdf”, pdfSaveOptions);
Hi,
The issues you have found earlier (filed as CELLSJAVA-41697) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.