XS0144 Error on Excel

This forum is meant for questions and discussions about the X# language and tools
Post Reply
stecosta66
Posts: 89
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

XS0144 Error on Excel

Post by stecosta66 »

Hi All,

when USING Microsoft.Office.Interop.Excel.Application at beginning of .prg I get the following error:

XS0144: Cannot create an instance of the abstract type or interface 'Microsoft.Office.Interop.Excel.GroupBox'

I think the reason is that a VO.Groupbox is already defined so I removed the USING directive and changed my code like that:

Code: Select all

	LOCAL oExcel                AS Microsoft.Office.Interop.Excel.Application
	LOCAL oWorkSheet            AS Microsoft.Office.Interop.Excel.Worksheet
	LOCAL oRange                AS Microsoft.Office.Interop.Excel.Range
	LOCAL oFont                 AS Microsoft.Office.Interop.Excel.Font
	LOCAL oWorkBooks            AS Microsoft.Office.Interop.Excel.Workbooks

	//... some other code
	
	oExcel := Microsoft.Office.Interop.Excel.Application{}

	oExcel:Visible := TRUE
	oExcel:ScreenUpdating := FALSE

	oWorkBooks := oExcel:Workbooks
	oWorkBooks:OpenText(cFile, uOrigin, uStartRow, uDataType, uTextQualifier, uConsecutiveDelimiter, uTab, uSemicolon, uComma,uSpace, uOther, uOtherChar, uFieldInfo)

	oWorkSheet := oExcel:ActiveSheet
	oRange := oWorkSheet:Range[cCol,cRow]
	oRange:SELECT()

	oFont := oRange:Font
	oFont:Name := "Courier New"
	oFont:Size := 10
	oFont:Strikethrough := FALSE
	oFont:Superscript := FALSE
	oFont:Subscript := FALSE
	oFont:OutlineFont := FALSE
	oFont:Shadow := FALSE

	oRange:Columns:AutoFit  // Adatta automaticamente le colonne
	oRange := oWorkSheet:Range[ "A1","A1"]
	oRange:SELECT()
but now I'm facing another error
XS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

on this line:

Code: Select all

	oRange:Columns:AutoFit  // Adatta automaticamente le colonne
How to solve this?

thanks
Stefano

P.S. I'm getting another error on this line of code

Code: Select all

	oWorkSheet:PageSetup:Orientation := 2 // xlLandascape
Error XS0266 Cannot implicitly convert type 'int' to 'Microsoft.Office.Interop.Excel.XlPageOrientation'. An explicit conversion exists (are you missing a cast?)
User avatar
wriedmann
Posts: 3784
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: XS0144 Error on Excel

Post by wriedmann »

Ciao Stefano,
I would say:
oRange:Columns:AutoFit()
as I think this should be a method call.
And use Intellisense to see the type of the oWorkSheet:PageSetup:Orientation - it should be an enumeration and a parameter similar to PageOrientation.xlLandscape
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
stecosta66
Posts: 89
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Re: XS0144 Error on Excel

Post by stecosta66 »

Ciao Wolfgang,

oRange:Columns:AutoFit() that was it, thanks!

as for second error, yes, it is an enumeration. I'v solved with:

oWorkSheet:PageSetup:Orientation := Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape

a lot of things to learn!

thanks!
Stefano

wriedmann wrote: Sat Dec 14, 2024 8:33 am Ciao Stefano,
I would say:
oRange:Columns:AutoFit()
as I think this should be a method call.
And use Intellisense to see the type of the oWorkSheet:PageSetup:Orientation - it should be an enumeration and a parameter similar to PageOrientation.xlLandscape
Wolfgang
Post Reply