Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[birt-dev] Birt Xlsx Emitter column width calculations

Hi All,

I am trying to write my custom Birt XSLX emitter. 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,
--
Parth Bhatt | Sr. Software Engineer | www.aivhub.com
This message is confidential, so please treat it appropriately and for its intended purpose only. In particular, if it refers to any technical data, terms or prices not generally available or known, such items are "commercially sensitive information" within the terms of the Freedom of Information Act 2000 and related laws. As it would be prejudicial to AIVHUB Ltd commercial interests if these were disclosed, please refrain from doing so. As Internet communications are not secure, please be aware that AIVHUB Ltd cannot accept responsibility for its contents. Any views or opinions presented are those of the author only and not of AIVHUB Ltd. If you are not the intended recipient of this e-mail, please accept our apologies and arrange for copies of it to be deleted. For your information, AIVHUB Ltd may intercept incoming and outgoing email communications.

Back to the top