Page 1 of 1

How to hide columns in Excel?

PostPosted: Thu Aug 10, 2017 4:47 am
by hua
Hi guys,
I couldn't get the code that I translated from Excel's macro to work to hide a column.

I was using
Code: Select all  Expand view
oSheet:columns("B:B"):EntireColumn:Hidden := .t.


Anyone with any suggestion to make it work?

Re: How to hide columns in Excel?

PostPosted: Thu Aug 10, 2017 3:03 pm
by Armando
hua:

It Works fine to me

Code: Select all  Expand view

    oSheet:Cells(nRow,10):Value := "Total del pronóstico:"
    oSheet:Cells(nRow,10):HorizontalAlignment := nRight
    oSheet:Cells(nRow,10):Font:Bold := (.T.)
    oSheet:Cells(nRow,11):Value := "=SUMA(K6:" + "K"+ALLTRIM(STR(nRow - 1,03,0)) + ")"
    oSheet:Cells(nRow,11):Font:Bold := (.T.)

    oSheet:Columns( "A" ):AutoFit()
    oSheet:Columns( "B" ):AutoFit()
    oSheet:Columns( "C" ):AutoFit()
    oSheet:Columns( "D" ):AutoFit()
    oSheet:Columns( "E" ):AutoFit()
    oSheet:Columns( "F" ):AutoFit()
    oSheet:Columns( "G" ):AutoFit()
    oSheet:Columns( "H" ):AutoFit()
    oSheet:Columns( "I" ):AutoFit()
    oSheet:Columns( "J" ):AutoFit()
    oSheet:Columns( "K" ):AutoFit()
    oSheet:Columns( "L" ):AutoFit()

    oSheet:Columns("B:B"):EntireColumn:Hidden := (.T.)       <-------------------------

    oExcel:Get("ActiveWorkBook"):SaveAs(ALLTRIM(oApp:cPathXlsx) +;
                                                     "PDP_" + DTOS(dFecPag) +;
                                                     ".Xlsx")
    oSheet:=NIL

    oExcel:Quit()
    oExcel:=NIL

 


Regards

Re: How to hide columns in Excel?

PostPosted: Fri Aug 11, 2017 10:34 am
by hua
Thank you for your feedback Armando.

You have helped confirmed that the syntax I used was correct.

Turns out at the last line in the closing function there is a line that says
Code: Select all  Expand view
oSheet:Columns("A:L"):autofit()
 


That line actually caused the hidden column to be unhidden

Re: How to hide columns in Excel?

PostPosted: Sat Aug 12, 2017 6:46 pm
by Armando
hua:

What a surprise :shock: , in my code that does not happen,
maybe it is the version of excel, I use the 2016 versión

Best rehards

Re: How to hide columns in Excel?

PostPosted: Mon Aug 14, 2017 1:57 am
by hua
Possible I guess. I am using 2010 version