Print Excel range with ExportAsFixedFormat or Printout

Print Excel range with ExportAsFixedFormat or Printout

SAPER59
Advocate Advocate
312 Views
3 Replies
Message 1 of 4

Print Excel range with ExportAsFixedFormat or Printout

SAPER59
Advocate
Advocate

I'm trying to print an excel sheet, filled with objects data and have seen that ExportAsFixedFormat could be the method, but can't make it works

The other option could be Printout but can't define the range and runing it, open an Excel dialog that I can't find the way to bypass, because after printing the first sheet, I need to write the cells with new data, print again, a couple of times.

Thanks in advance

0 Likes
313 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

If this is a excel question ?

 

Have you googled or maybe joined an Excel forum and ask for answers.

0 Likes
Message 3 of 4

SAPER59
Advocate
Advocate

No, what I'm trying to find is the way to print the Excel file filled inside VisualLisp routin with objects data, extracted

The point is that I can handled from Visual Lisp to write, read, adjust cells, width , colors, etc, but can't find the way to, ones the files is ready, other than save it as an XLS file, I need to print a range to a PDF, and investigating I found that can be done with PRINTOUT selecting a PDF printer from those available, but found 2 problems, one is I can't control de range, and it opens and Excel dialog, that interruput the routin, so I lost the control and can't go ahead with others files with different data. I read too that . ExportAsFixedFormat  can do the same, but passing the parameters, I can not make it works, so I'm sure there's something wrong in my procedure, so I'm trying to find some  one that could have done it or know how. 

(vlax-put-property XL "ActivePrinter" "DocuCom PDF Driver on Ne03:")
(vlax-invoke-method XLS "Printout")

but can't control it

 

The other can be reached  by  (vlax-invoke-method XLS "ExportAsFixedFormat" 0 filename)

Sub ExportAsFixedFormat(Type As XlFixedFormatType, [Filename], [Quality], [IncludeDocProperties], [IgnorePrintAreas], [From], [To], [OpenAfterPublish], [FixedFormatExtClassPtr]) Member of Excel.Chart

 

 

 

0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

No idea really but this line shows how lots of answers are required for SAVE. Would expect similar for print. 

 

(vlax-invoke-method (vlax-get-property myxl "ActiveWorkbook") "SaveAs" filename -4143 "" "" :vlax-false :vlax-false nil )

A get range method by Fixo he provided lots of excel stuff was way ahead of people like me.

 

; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma 9 is tab 34 is space 58 is colon
(defun _csv->lst58 ( str / pos )
	(if (setq pos (vl-string-position 58 str))
		(cons (substr str 1 pos) (_csv->lst58 (substr str (+ pos 2))))
		(list str)
    )
)

; Thanks to fixo for this
(defun getrangexl2 ( / lst UR CR RADD )
(vl-catch-all-error-p
	   (setq Rng
		  (vl-catch-all-apply
		    (function (lambda ()
				(vlax-variant-value
				  (vlax-invoke-method
				    (vlax-get-property myxl 'Application)
				    'Inputbox
				    "Select a Range: "
				    "Range Selection Example"
				    nil
				    nil
				    nil
				    nil
				    nil
				    8))))))
)
(setq xrng (vlax-get-property rng "address"))
(setq xxrng xrng)
(repeat 4 (setq xxrng(vl-string-subst "" "$" xxrng)))
(setq xxxrng (_csv->lst58 xxrng))
(setq rngst (columnrow (nth 0 xxxrng)) rngend (columnrow (nth 1 xxxrng)))
(setq *ExcelData@ nil )
(setq Row# (nth 1 rngst))
(repeat (+ (- (nth 1 rngend)(nth 1 rngst) ) 1)
(setq Data@ nil)
(setq Column# (nth 0 rngst))
(repeat (+  (- (nth  0 rngend)(nth 0 rngst) ) 1)
(setq Range$ (strcat (Number2Alpha Column#)(itoa Row#)))
(setq ExcelRange (vlax-get-property myxl "Range" range$))
(setq ExcelVariant (vlax-get-property ExcelRange 'Value))
(setq ExcelValue (vlax-variant-value ExcelVariant))
(setq Data@ (append Data@ (list ExcelValue)))
(setq Column# (1+ Column#))
)
(setq *ExcelData@ (append *ExcelData@ (list Data@)))
(setq Row# (1+ Row#))
)
(princ)
)

 

 

0 Likes