Setting a column's charwidth isn't accurate

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
robhoney
Posts: 1
Joined: Fri Jul 06, 2007 12:45 pm

Setting a column's charwidth isn't accurate

Post by robhoney »

Hello,

I'm trying to produce some reports with specific column widths needed. The problem is that whenever I specify a CharWidth the end result is something a bit less than the CharWidth I specified. I've tried setting width instead (256 * charwidth) but that didn't work either.

Is there a way I can specifiy a specific CharWidth?

Regards

Rob H
(Kilclare Software)
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Post by larsa »

Hello

The character width used here is an excel character width, that not is the same as normal character width given by api functions, such as LOGFONT. You have to try until you get the width that you want.


Lars Arvidsson
Joe Griffin
Posts: 13
Joined: Tue Feb 13, 2007 8:47 am
Location: West Sussex England

Column widths

Post by Joe Griffin »

I had this problem and found it better to use PixelWidth, so I wrote the following function:

function xlsPixelWidth(CharWidth: Double): Integer;
begin
// Returns an adjusted width for a work-around in xlsReadWrite
Result := Trunc(7 * CharWidth) + 5;
end;

Then I simply use (for example)

Columns[0].PixelWidth := xlsPixelWidth(6);

Hope that helps
Joe Griffin
GerbilSoft Associates Limited
Post Reply