Add method AQExcelSpreadsheet.setCell( row, col, value, Font, backgroundColor, foregroundColor )
7 KB
@Niels: I will add AQColor and AQFont interfaces and corresponding factory classes to support the requested API. If you have different thoughts please let me know.
Done:
SVN r44894/15.0.16-1
SVN r44896/16.0.5-22
SVN r44899/17.0.0-dev-90
I needed to add a few lines to WorksheetExcel.setCellStyle(String cell, CellStyle style)
(a low level API, WorksheetExcel has been rename to AsposeWorksheet in trunk) in order to get font settings applied to Aspose; not sure if this is an ADS bug or due to Aspose library changes.
An example script is included below to demonstrate how to create color and font objects and pass them to the newly added AQExcelSpreadsheet.setCell(row, col, value, AQFont, AQColor, AQColor)
API. The ExampleOutput screenshot shows the output of this example script.
// This script demonstrates how to set font, background color and foreground color in an Excel cell.
var book = aqua.data.excelSpreadsheet('C://tmp/excel/cellStyleExample.xls');
var fontFactory = aqua.type.font;
var headerFont = fontFactory.newFont("Arial", fontFactory.BOLD, 12);
var valueFont = fontFactory.newFont("Courier New");
var footerFont = fontFactory.newFont("Times New Roman", fontFactory.BOLD | fontFactory.ITALIC, 11);
var colorFactory = aqua.type.color;
var headerBg = colorFactory.getYellow();
var headerFg = colorFactory.getRed();
var valueBg = colorFactory.getGreen();
var valueFg = colorFactory.newColor(0, 100, 255);
book.currentWorksheet = "Cell Style Demo";
// customize cell's font, background color and foreground color
book.setCell(0, 0, 'Header 1', headerFont, headerBg, headerFg);
book.setCell(0, 1, 'Header 2', headerFont, headerBg, headerFg);
book.setCell(0, 2, 'Header 3', headerFont, headerBg, headerFg);
// customize cell's font, background color and foreground color
book.setCell(1, 0, 'Value 11', valueFont, valueBg, valueFg);
book.setCell(1, 1, 'Value 12', valueFont, valueBg, valueFg);
book.setCell(1, 2, 'Value 13', valueFont, valueBg, valueFg);
// only customize cell's font
book.setCell(2, 0, 'Value 21', valueFont, null, null);
// only customize cell's background color
book.setCell(2, 1, 'Value 22', null, valueBg.brighter(), null);
// only customize cell's foreground color
book.setCell(2, 2, 'Value 23', null, null, valueFg.darker());
// no customization
book.setCell(3, 0, 'Remark:');
// only customize cell's font
book.setCell(3, 1, 'Example', footerFont, null, null);
book.autoResize = true;
book.save();
aqua.console.println("Excel Cell Style Example - Done");
Done:
SVN r44894/15.0.16-1
SVN r44896/16.0.5-22
SVN r44899/17.0.0-dev-90
I needed to add a few lines to WorksheetExcel.setCellStyle(String cell, CellStyle style)
(a low level API, WorksheetExcel has been rename to AsposeWorksheet in trunk) in order to get font settings applied to Aspose; not sure if this is an ADS bug or due to Aspose library changes.
An example script is included below to demonstrate how to create color and font objects and pass them to the newly added AQExcelSpreadsheet.setCell(row, col, value, AQFont, AQColor, AQColor)
API. The ExampleOutput screenshot shows the output of this example script.
// This script demonstrates how to set font, background color and foreground color in an Excel cell.
var book = aqua.data.excelSpreadsheet('C://tmp/excel/cellStyleExample.xls');
var fontFactory = aqua.type.font;
var headerFont = fontFactory.newFont("Arial", fontFactory.BOLD, 12);
var valueFont = fontFactory.newFont("Courier New");
var footerFont = fontFactory.newFont("Times New Roman", fontFactory.BOLD | fontFactory.ITALIC, 11);
var colorFactory = aqua.type.color;
var headerBg = colorFactory.getYellow();
var headerFg = colorFactory.getRed();
var valueBg = colorFactory.getGreen();
var valueFg = colorFactory.newColor(0, 100, 255);
book.currentWorksheet = "Cell Style Demo";
// customize cell's font, background color and foreground color
book.setCell(0, 0, 'Header 1', headerFont, headerBg, headerFg);
book.setCell(0, 1, 'Header 2', headerFont, headerBg, headerFg);
book.setCell(0, 2, 'Header 3', headerFont, headerBg, headerFg);
// customize cell's font, background color and foreground color
book.setCell(1, 0, 'Value 11', valueFont, valueBg, valueFg);
book.setCell(1, 1, 'Value 12', valueFont, valueBg, valueFg);
book.setCell(1, 2, 'Value 13', valueFont, valueBg, valueFg);
// only customize cell's font
book.setCell(2, 0, 'Value 21', valueFont, null, null);
// only customize cell's background color
book.setCell(2, 1, 'Value 22', null, valueBg.brighter(), null);
// only customize cell's foreground color
book.setCell(2, 2, 'Value 23', null, null, valueFg.darker());
// no customization
book.setCell(3, 0, 'Remark:');
// only customize cell's font
book.setCell(3, 1, 'Example', footerFont, null, null);
book.autoResize = true;
book.save();
aqua.console.println("Excel Cell Style Example - Done");
Apologies, but I didn't see your comment until now. I would have chosen to keep the method simple and not create AQColor and AQFont. But I wasn't sure which would be the best choice. The current implementation should be fine.
Apologies, but I didn't see your comment until now. I would have chosen to keep the method simple and not create AQColor and AQFont. But I wasn't sure which would be the best choice. The current implementation should be fine.
No problem, Niels. I was not sure what kinds of objects are allowed to be passed from script to ADS; javascript is typeless, it's a bit difficult to create color and font 'object' on the script side directly. That's why I implemented AQColor and AQFont.
No problem, Niels. I was not sure what kinds of objects are allowed to be passed from script to ADS; javascript is typeless, it's a bit difficult to create color and font 'object' on the script side directly. That's why I implemented AQColor and AQFont.
Issue #13570 |
Closed |
Fixed |
Resolved |
Completion |
No due date |
Fixed Build ADS 15.0.16-1/16.0.5-22/17.0.0-dev-90 |
No time estimate |
2 issue links |
relates to #13583
Issue #13583AQColor and AQFont interfaces and their corresponding classes are not added in Open API documentation. |
relates to #13582
Issue #13582AQColor and AQFont interfaces and their corresponding classes are not added in Open API auto completion. |
@Niels: I will add AQColor and AQFont interfaces and corresponding factory classes to support the requested API. If you have different thoughts please let me know.