exceljs / exceljs

Excel Workbook Manager
MIT License
13.8k stars 1.76k forks source link

Windows scaling of texts and elements affects the height of rows #743

Open fbele opened 5 years ago

fbele commented 5 years ago

Hi, I am using my laptop that is connected with an external monitor for developing my excel file export. This monitor has a default setting of 100% scaling by Windows. When I set height of a row, for example worksheet.getRow(1).height = 50 and then export (download) and open the file in Excel, the height of the row is as expected, 50.

But, when I unplug the monitor from the laptop, I have a Scaling of Windows scaling of texts and elements of 150%, because the laptop has high resolution. In this case I really get strange behavior. If I open the same downloaded file again with Excel, the rows height are not the same anymore. They get narrower for just about the ratio of the Windows's scaling.

I have never encountered that before and nothing I do seems to help. Does anybody have any experience like that?

Thank you very much in advance.

Siemienik commented 5 years ago

hmm... it's really interesting, I have similar display set and It's work fine for me.

anyone can write some more info?

fbele commented 5 years ago

Hi,

First, I would like to point out, that I am using a browser version with Angular 7.

I think I actually resolved the issue by myself. The only thing that I did is added 'views' property to my worksheet and it got in order. One can add just an array with an empty object as a value and it is ok.

const worksheet = workbook.addWorksheet('Sheet', { views: [{}] });

Although I do use 'zooming' parameter of the 'views' property, 'defaultRowHeight' parameter of the 'properties' property and additional settings to 'pageSetup' property:

const worksheet = workbook.addWorksheet('Sheet', { properties: { defaultRowHeight: 15 }, pageSetup: { paperSize : 9, orientation : 'portrait', fitToPage : true, fitToWidth : 1, fitToHeight : 0 }, views: [{ zoomScale : 85, zoomScaleNormal : 100 }] });

First of all I would point out, that this is just an observation of mine and a suspicion, what could be happening to cause this error.

So there are actually four situations:

  1. Laptop with 150% scaling setting + connected external monitor as extended screen with 100% scaling setting = OK on both monitors
  2. Laptop with closed lid + connected external monitor with 100% scaling setting = OK on external monitor
  3. Laptop + connected external monitor as duplicated screen with 100% scaling setting = NOT OK on both monitors
  4. Only laptop with 150% scaling setting = NOT OK on both monitors

I am adding my rows in this manor:

worksheet.addRow().height = 36; worksheet.addRow().height = 48; worksheet.addRow().height = 18.75; worksheet.addRow().height = 18.75; worksheet.addRow().height = 19.50; worksheet.addRow().height = 16.50; worksheet.addRow(); worksheet.addRow().height = 29.25; worksheet.addRow();

Even though the issue is resolved, I hope I help somebody in the future with the same issue.

Regards

robertocerdasilva commented 3 years ago

@fbele bro, this has helped me tremendously! Such a simple solution to a problem that I didn't understand why. If it is not in the documentation they should add it.

Thank you!