EasyXLS
http://forum.easyxls.com/

Autofit Column in VB 6
http://forum.easyxls.com/viewtopic.php?f=5&t=2283
Page 1 of 1

Author:  opingo [ Wed Aug 16, 2023 2:49 pm ]
Post subject:  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

Author:  daniela [ Fri Aug 18, 2023 8:45 am ]
Post subject:  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.

Author:  opingo [ Mon Aug 21, 2023 6:02 am ]
Post subject:  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 2464 times

Author:  daniela [ Mon Aug 28, 2023 8:02 am ]
Post subject:  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.

Author:  opingo [ Thu Aug 31, 2023 7:08 am ]
Post subject:  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 27197 times ]
File comment: This is the Current Auto Fit. Check Colum H and K
Current AutoFit.jpg
Current AutoFit.jpg [ 45.27 KiB | Viewed 27197 times ]

Author:  daniela [ Tue Sep 05, 2023 9:26 am ]
Post subject:  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.

Page 1 of 1 All times are UTC - 4 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/