Reply to topic  [ 6 posts ] 
Autofit Column in VB 6 
Author Message

Joined: Wed May 24, 2023 1:00 am
Posts: 6
Reply with quote
Post Autofit Column in VB 6
I have Following Query for EasyXLS for VB 6 for doing Autofit of Column

How to do Autofit all the column ?

I have tried the Following
xlsFirstTable.setColumnWidth -1 Autofit does not work and Excel File Gives Error while opening saying that It has found unreadable contenet in Excel File

xlsFirstTable.setColumnWidth 0 It does work many times, but it does not work with Numbers.

Following is the Code which I have Tried.

Dim workbook
Dim xlsFirstTable
Dim xlsStyleBold

Set workbook = CreateObject("EasyXLS.ExcelDocument")
Set xlsStyleBold = CreateObject("EasyXLS.ExcelStyle")

workbook.easy_addWorksheet_2 ("S1")


Set xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
xlsFirstTable.setColumnWidth 0

xlsFirstTable.easy_getCell(0, 0).setValue ("Sheet 1")

xlsFirstTable.easy_getCell(4, 0).setValue ("Column 1")
xlsFirstTable.easy_getCell(4, 1).setValue ("Column 2")
xlsFirstTable.easy_getCell(4, 2).setValue ("3")
xlsFirstTable.easy_getCell(4, 3).setValue ("Column 4")
xlsFirstTable.easy_getCell(4, 4).setValue ("Column 5")
xlsFirstTable.easy_getCell(4, 5).setValue ("Column 6")
xlsFirstTable.easy_getCell(4, 6).setValue ("Column 7")
xlsFirstTable.easy_getCell(4, 7).setValue ("8")
xlsFirstTable.easy_getCell(4, <- src="{SMILIES_PATH}/icon_cool.gif" alt="8)" title="Cool" />.setValue ("Column 9")
xlsFirstTable.easy_getCell(4, 9).setValue ("Column 10")
xlsFirstTable.easy_getCell(4, 10).setValue ("10")
xlsFirstTable.easy_getCell(4, 11).setValue ("Column 11")
xlsFirstTable.easy_getCell(4, 12).setValue ("12")

xlsFirstTable.easy_getCell(5, 2).setValue ("321")
xlsFirstTable.easy_getCell(5, 5).setValue ("Column 6 Value 123")
xlsFirstTable.easy_getCell(5, 7).setValue (123456789.12)
xlsFirstTable.easy_getCell(5, 10).setValue (12345.12)
xlsFirstTable.easy_getCell(5, 7).setDataType ("numeric")
xlsFirstTable.easy_getCell(5, 10).setDataType ("numeric")

xlsStyleBold.setBold (True)
xlsStyleBold.setHorizontalAlignment ("center")

Err = xlsFirstTable.easy_setRangeStyle(4, 0, 4, 12, xlsStyleBold) = True


str1 = App.Path + "\Test.xlsx"

workbook.easy_WriteXLSXFile (str1)

Now in the above Code You need to Check Column H and Column K. It does not Authfir

Can You Help me to correct the above Code or give the Sample code to do AutoFit of the all the column in VB 6.0?

Thanking You,

Bhavesh


Wed Aug 16, 2023 2:49 pm
Profile

Joined: Fri Feb 03, 2006 12:23 pm
Posts: 199
Location: Brasov, Romania
Reply with quote
Post Re: Autofit Column in VB 6
Hi,

ExcelTable.setColumnWidth(int) method having one parameter sets the default column width and usually is visible for undefined columns.
ExcelTable.setColumnWidth(int,int) method having two parameters sets the column width for a specific column:
https://www.easyxls.com/manual/API_Documentation/EasyXLS/ExcelTable.html#setColumnWidth(int,int)

In your case, if you don't set the column width, it should be automatically computed. This is the default behavior.

Related to your code, the part with the GIF image does not appear to be right.

_________________
EasyXLS Team
.NET and Java library to read and write Excel files
Facebook X Reddit LinkedIn


Fri Aug 18, 2023 8:45 am
Profile WWW

Joined: Wed May 24, 2023 1:00 am
Posts: 6
Reply with quote
Post Re: Autofit Column in VB 6
Dear Daniela,

I have already gone through the Links but I am not able to find the Solution Inspite of Trying Multiple times.

Kindly find Project with the Source Code and this will generate the Excel File.

Thanking You,

Bhavesh


Attachments:
Test.zip [12.36 KiB]
Downloaded 8260 times
Mon Aug 21, 2023 6:02 am
Profile

Joined: Fri Feb 03, 2006 12:23 pm
Posts: 199
Location: Brasov, Romania
Reply with quote
Post Re: Autofit Column in VB 6
Between the following lines, the first one is better because setValue method accepts string parameter:
Code:
xlsFirstTable.easy_getCell(5, 7).setValue ("123456789.12")
xlsFirstTable.easy_getCell(5, 10).setValue (123456.12)


The column width seams fine for all columns. No data is truncated. The numeric values have indeed a small gap in front of the value, but this assures extra space for complex number formats.

_________________
EasyXLS Team
.NET and Java library to read and write Excel files
Facebook X Reddit LinkedIn


Mon Aug 28, 2023 8:02 am
Profile WWW

Joined: Wed May 24, 2023 1:00 am
Posts: 6
Reply with quote
Post Re: Autofit Column in VB 6
Dear Daniela,

I am uploading the Screen Shots and Excel Files

This is the Current Auto Fit.

Check Colum H and K and You will find the Extra Space

Is there any Way to Remove the Extra Spaces ?

Bhavesh


Attachments:
File comment: This is what Auto Fit Should do
IdeaL AutoFit.jpg
IdeaL AutoFit.jpg [ 49.45 KiB | Viewed 64316 times ]
File comment: This is the Current Auto Fit. Check Colum H and K
Current AutoFit.jpg
Current AutoFit.jpg [ 45.27 KiB | Viewed 64316 times ]
Thu Aug 31, 2023 7:08 am
Profile

Joined: Fri Feb 03, 2006 12:23 pm
Posts: 199
Location: Brasov, Romania
Reply with quote
Post Re: Autofit Column in VB 6
Hi,

If you keep the value as numeric, it will keep an extra space reserved in front of the value for any eventual formatting. It is not possible to remove the extra space in this case.
If you will set a data type as string for the numeric value, the space will disappear, but if you will use the cell inside a formula, it will be considered as string.

_________________
EasyXLS Team
.NET and Java library to read and write Excel files
Facebook X Reddit LinkedIn


Tue Sep 05, 2023 9:26 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.