How to calculate xlsx columns width from page coordinates? [message #1847812] |
Tue, 09 November 2021 06:53 |
Eclipse User |
|
|
|
Hi All,
I am trying to write my custom Birt XSLX emitter as supdsoft emitter have some limitations. I am using birt 4.6 and it is working quite well, but when I try to calculate column width using page coordinates it's not calculated properly.
Could anyone let me know how to calculate it properly. Here is my below code:
@Override
public void endSheet(Page page, String orientation, int pageWidth, int pageHeight, float leftMargin,
float rightMargin, float topMargin, float bottomMargin) {
double[] coordinates = page.getCoordinates();
for (byte i = 0; i < coordinates.length; i++) {
this.sheet.setColumnWidth(i, (int) calulateWidth(coordinates[i]/1000.0D, 96) * 256);
}
}
public static double calulateWidth(double width, int dpi) {
float PX_PT = 72.0 / dpi;
if ( width < 0 )
return 0;
double result = 0;
double widthInPixel = width / PX_PT;
double digitalWidth = 7;
// convert from pixel to number of charaters
result = (int) ( ( widthInPixel - 5 ) / digitalWidth * 100 + 0.5 );
double characterNumber = (double) result / 100;
// calculate characterNumber
result = (int) ( ( characterNumber * digitalWidth + 5 ) / digitalWidth * 256 );
return result / 256;
}
If someone can help that will be great.
Regards,
|
|
|
Powered by
FUDForum. Page generated in 0.04523 seconds