Author Topic: setting an Excel cell font  (Read 2515 times)

0 Members and 1 Guest are viewing this topic.

danadrian.baluta@yahoo.co

  • Guest
setting an Excel cell font
« on: June 23, 2015, 06:56:06 AM »
Hi,

Using the internet resources I managed to write a program that exports four lists to Excel.
But I would like to add a fifth list that tells me if the font for the cells should be bold.
I don't know how to change the bold property of the font property of a certain cell.

Here is the code that I have so far:

Code - Auto/Visual Lisp: [Select]
  1. (setq excel (vlax-create-object "Excel.Application")
  2.         workbooks (vlax-get-property excel 'Workbooks)
  3.         currworkbook (vlax-invoke-method workbooks 'Open "P:\\CAD Archive\\Autolisp\\CutbackAreaTemplate.xls")
  4.         activesheet (vlax-get-property excel 'ActiveSheet)
  5.         cells (vlax-get-property activesheet 'Cells)
  6.   rows (length datafl)
  7.   ct 1)
  8.   (while (<= ct rows)
  9.     (vlax-put-property cells 'Item ct 1 (nth (1- ct) datafl))
  10.     (vlax-put-property cells 'Item ct 2 (nth (1- ct) dataz))
  11.     (vlax-put-property cells 'Item ct 3 (nth (1- ct) datarea))
  12.     (vlax-put-property cells 'Item ct 4 (nth (1- ct) datareaft))
  13.   (setq ct (1+ ct))
  14.   )
  15.   (setq rezultat (vl-catch-all-apply 'vlax-invoke-method (list currworkbook 'SaveAs filename -4143 nil nil :vlax-false :vlax-false 1 2)))
  16.   ;(vlax-invoke-method currworkbook 'SaveAs filename -4143 nil nil :vlax-false :vlax-false 1 2)
  17.   (vlax-invoke-method workbooks 'Close)
  18.   (vlax-release-object activesheet)
  19.   (vlax-release-object currworkbook)
  20.   (vlax-release-object workbooks)
  21.   (gc)

I would be greatful for any hint or advice.
Thank you,
Adrian

kpblc

  • Bull Frog
  • Posts: 396
Re: setting an Excel cell font
« Reply #1 on: June 23, 2015, 07:20:30 AM »
I think something like this:
(vlax-put-property cell 'font "bold" :vlax-true)

Right now I write under Linux OS, I haven't any software to check code ((
Sorry for my English.

danadrian.baluta@yahoo.co

  • Guest
Re: setting an Excel cell font
« Reply #2 on: June 23, 2015, 09:34:08 AM »
Thank you kpblc,

I would do that but i'm a beginner in this vlisp-excel thing.
In my program I call a cell as a property of cells
Code - Auto/Visual Lisp: [Select]
  1. (vlax-put-property cells 'Item ct 1 (nth (1- ct) datafl))
I would need something like
Code - Auto/Visual Lisp: [Select]
  1. (setq cell (vlax-get-property cells 'Item ct 1))
to be able to identify a cell and then change its properties, but what I wrote doesn't work.
Any ideas?

I have a lot of basic questions like this.
I would pay for some training or a book that sheds light on visual lisp, but I don't know any. If anybody could recommend some, I would be grateful.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: setting an Excel cell font
« Reply #3 on: June 23, 2015, 10:27:52 AM »
Maybe this will give you some examples you could use.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: setting an Excel cell font
« Reply #4 on: June 23, 2015, 10:29:02 AM »
I do not have any direct help, but these links may provide some help.

Object model for Excel 2013
https://msdn.microsoft.com/en-us/library/office/ff194068.aspx

On the application page above, this is shown, so maybe something like this this would work for you
Application.ActiveCell.Font.Bold = True

Samples and the ability to buy their product for programming VBA in Excel ( I have never used this site/product before )
http://www.excel-vba.com/excel-vba-solutions-beginners.htm
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.