Excel Writer improvements

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2823
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Excel Writer improvements

Post by Michael Vogel »

I have made some adaptions (Date functions etc.) in the original ExcelWriter include file and added a possibility to create colored text (XlsSetFontColor), which works fine. This library is very useful, because it's resulting files can be opened in a wide range of spreadsheet programs and versions. On the other hand, there are some restrictions, so in the future, a support for BIFF4 or BIFF5 could be nice target.

But beside this, I have some problems with the given functions as well, like number the number format and some font issues.

1a) there are some predefined number formats (0-22), which will automatically be adapted to the regional settings (at least from excel). Most of the formats (0-20) work fine, as you can see when starting the example below. But if you change the for/next loop to include the format 21 or 22, the resulting file can't be opened without crashing.
Any ideas how to use number format 21 and 22 in a spreadsheet?

1b) does anyone know, how to create a user defined number format, like 'mm:ss' or '0.000' ?

2) there are still problems to create certain text cells, so the cell A2 in the example below stays white after loading the created 'test.xls' into excel. Also here, does anyone know, if this problem can be resolved?

Code: Select all

;~~~~

IncludeFile "ExcelWriter (Ori).pbi"

;~~~~

Global XlsActiveFile=#True

#Q=Chr(34)

#XlsFont1			=	0
#XlsFont2			=	64
#XlsFont3			=	128
#XlsFont4			=	192

#XlsCellNormal	=	0
#XlsCellLocked	=	64
#XlsCellHidden	=	128

#XlsMarginLeft	=	38
#XlsMarginRight	=	39
#XlsMarginTop		=	40
#XlsMarginBottom	=	41

#XlsNoFormat		=	0
#XlsBold			=	1
#XlsItalic			=	2
#XlsUnderline		=	4
#XlsStrikeout		=	8

#XlsNoAlignment		=	0
#XlsAlignmentNull		=	0
#XlsAlignmentLeft		=	1
#XlsAlignmentCenter	=	2
#XlsAlignmentRight	=	3
#XlsCellFill				=	4
#XlsNoBorder			=	0
#XlsBorderNull			=	0
#XlsBorderLeft		=	8
#XlsBorderRight		=	16
#XlsBorderTop			=	32
#XlsBorderBottom		=	64
#XlsCellShaded		=	128

Enumeration
	#XlsFormat_Nil
	#XlsFormat_General
	#XlsFormat_Number1
	#XlsFormat_Number2
	#XlsFormat_Number3
	#XlsFormat_Number4
	#XlsFormat_Currency1
	#XlsFormat_Currency2
	#XlsFormat_Currency3
	#XlsFormat_Currency4
	#XlsFormat_Percent1
	#XlsFormat_Percent2
	#XlsFormat_Scientific
	#XlsFormat_DateLong
	#XlsFormat_DateStandard
	#XlsFormat_DateShort
	#XlsFormat_TimeShort
	#XlsFormat_TimeLong
	#XlsFormat_TimeShort24
	#XlsFormat_TimeLong24
	#XlsFormat_DateTime
	#XlsFormat_Scientific2
	#XlsFormat_TimeMinutes
	#XlsFormat_Text
	#XlsFormat_PrivateNumber
	#XlsFormat_PrivateTime
EndEnumeration

; ~~~

Structure XlsFontColorType
	opcode.w; 	69 (0x45)
	length.w; 		2 (0x02)
	Color.w; 		color-code (2 byte)
EndStructure

Structure XlsNumberType
	opcode.w;		03 (0x03)
	length.w;		15 (0x0F)
	Row.w;		row (2 byte)
	col.w;			column (2 byte)
	rgbAttr1.b;		hidden [7], locked [6], XF-index [0-5] (1 byte)
	rgbAttr2.b;		font [6-7], format [0-5] (1 byte)
	rgbAttr3.b;		shade [7], borders [3-6], alignment [0-2] (1 byte)
	Value.d;		double (8 bytes)
EndStructure

Structure XlsFontType
	opcode.w;			49 (0x31)
	length.w;			5+len(fontname)
	FontHeight.w;		height (2 byte)
	FontAttributes1.b;		extended [7], condensed [6], shadowed [5], outlined [4], strikeout [3], underline [2], italic [1], bold [0]
	FontAttributes2.b;		reserved - always 0 (1 byte)
	FontNameLength.b;	(1 byte)
EndStructure

; ~~~

Procedure.d IpfTimeToDouble(hour,minute,second)

	ProcedureReturn (hour*3600+minute*60+second)/86400.0

EndProcedure
Procedure.l IpfDateToJulian(year,month,day)

	Protected Elapsed=day

	If month<3
		month+12
		year-1
	EndIf

	Elapsed+Int((year+4712)*365.25)
	Elapsed-year/100
	Elapsed+year/400
	Elapsed+Int(30.6*month-30.4)

	ProcedureReturn Elapsed

EndProcedure
Procedure.l IpfWriteStringToFile(String.s)

	Protected Bytes.l

	CompilerIf #PB_Compiler_Unicode

		Protected *Buffer=AllocateMemory(Len(String)+2)

		If *Buffer
			PokeS(*Buffer,String,Len(String),#PB_Ascii)
			WriteFile_(XlsActiveFile,*Buffer,Len(String),@Bytes,0)
			FreeMemory(*Buffer)
		EndIf

	CompilerElse

		WriteFile_(XlsActiveFile,@String,Len(String),@Bytes,0)

	CompilerEndIf

	ProcedureReturn Bytes

EndProcedure
Procedure.l XlsSetFont(FontName$,FontHeight.l,FontFormat.l)

	If XlsActiveFile=0
		ProcedureReturn #False
	EndIf

	XlsFontData.XlsFontType
	XlsFontData\opcode=49
	XlsFontData\length=5+Len(FontName$)
	XlsFontData\FontHeight=FontHeight*20
	XlsFontData\FontAttributes1=FontFormat & $FF ;bold/underline etc...
	XlsFontData\FontAttributes2=0                ;reserved-always zero!!
	XlsFontData\FontNameLength=Len(FontName$) & $FF

	If Ipf_WriteToFile(XlsFontData,SizeOf(XlsFontType))
		ProcedureReturn IpfWriteStringToFile(FontName$)
	EndIf

EndProcedure
Procedure.l XlsSetFontcolor(FontColor.l)
	
	If XlsActiveFile=0
		ProcedureReturn #False
	EndIf
		
	XlsFontColorData.XlsFontColorType
	XlsFontColorData\opcode=69;	$45
	XlsFontColorData\length=2
	Select FontColor
	Case #Black
		XlsFontColorData\Color=0
	Case #White
		XlsFontColorData\Color=1
	Case #Red
		XlsFontColorData\Color=2
	Case #Green
		XlsFontColorData\Color=3
	Case #Blue
		XlsFontColorData\Color=4
	Case #Yellow
		XlsFontColorData\Color=5
	Case #Magenta
		XlsFontColorData\Color=6
	Case #Cyan
		XlsFontColorData\Color=7
	Default
		XlsFontColorData\Color=0
	EndSelect

	If Ipf_WriteToFile(XlsFontColorData,SizeOf(XlsFontColorType))
		ProcedureReturn #True
	EndIf

EndProcedure
Procedure.l XlsWriteDate(year,month,day,hour,minute,second,row.l,col.l,CellFont.l,CellAlignment.l,HiddenLocked.l,CellFormat.l)

	If XlsActiveFile=0
		ProcedureReturn #False
	EndIf

	XlsNumberData.XlsNumberType
	XlsNumberData\opcode=3
	XlsNumberData\length=15
	XlsNumberData\row=row & $FFFF
	XlsNumberData\col=col & $FFFF
	XlsNumberData\rgbAttr1=HiddenLocked & $FF
	XlsNumberData\rgbAttr2=CellFont|CellFormat & $FF
	XlsNumberData\rgbAttr3=CellAlignment & $FF
	XlsNumberData\Value=IpfDateToJulian(year,month,day)-IpfDateToJulian(1899,12,31)+IpfTimeToDouble(hour,minute,second)

	ProcedureReturn Ipf_WriteToFile(XlsNumberData,SizeOf(XlsNumberType))

EndProcedure
Procedure.l XlsWriteDateString(Date.s,DateFormat.s,row.l,col.l,CellFont.l,CellAlignment.l,HiddenLocked.l,CellFormat.l)

	Protected o

	o=ParseDate(DateFormat,Date)

	If o
		ProcedureReturn XlsWriteDate(Year(o),Month(o),Day(o),Hour(o),Minute(o),Second(o),row.l,col.l,CellFont.l,CellAlignment.l,HiddenLocked.l,CellFormat.l)
	Else
		ProcedureReturn #False
	EndIf

EndProcedure

; ~~~

Xls_CreateFile("Test.xls")
Xls_PrintGridLines(#False)

Xls_SetFont("Calibri",12,#XlsNoFormat)
XlsSetFontcolor(#Black)
Xls_SetFont("Calibri",12,#XlsBold)
XlsSetFontcolor(#Blue)
Xls_SetFont("Calibri",18,#XlsBold)
XlsSetFontcolor(#Red)
Xls_SetFont("Calibri",12,#XlsBold)
XlsSetFontcolor(#Green)

Xls_SetColumnWidth(0,0,20)
Xls_SetColumnWidth(1,1,5)
Xls_SetRowHeight(1,24)
Xls_WriteText("Excel Writer 1.51",1,0,#XlsFont3,#XlsAlignmentLeft,#XlsCellNormal|#XlsCellLocked,#Null)

For i=1 To 4
	Xls_WriteText(Chr('@'+i),3,i-1,#XlsFont2,#XlsAlignmentCenter|#XlsBorderBottom,#XlsCellNormal,#Null)
	Xls_WriteNumber(Random(300)/10,4,i-1,#XlsFont1,#XlsAlignmentRight,#XlsCellNormal,#XlsFormat_Number3)
	Xls_WriteNumber(Random(300)/10,5,i-1,#XlsFont2,#XlsAlignmentRight|#XlsBorderTop,#XlsCellNormal,#XlsFormat_Number3)
Next i

XlsWriteDateString("20121224112233","%YYYY%MM%DD%HH%II%SS",7,0,#XlsFont1,#XlsAlignmentLeft,#XlsCellNormal,#XlsFormat_DateTime)
XlsWriteDate(2012,12,24,11,22,33,6,0,#XlsFont1,#XlsAlignmentLeft,#XlsCellNormal,#XlsFormat_TimeLong24)

For i=0 To 20; 21, 22 !!!!!
	Xls_WriteNumber(i,8+i,1,#XlsFont1,#XlsAlignmentRight,#XlsCellNormal,#XlsFormat_Nil)
	Xls_WriteNumber(123.45,8+i,0,#XlsFont1,#XlsAlignmentRight,#XlsCellNormal,#XlsFormat_Nil+i)
Next i

Xls_CloseFile()
Last edited by Michael Vogel on Thu Dec 27, 2012 8:33 am, edited 1 time in total.
User avatar
Michael Vogel
Addict
Addict
Posts: 2823
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Excel Writer improvements

Post by Michael Vogel »

If you like to create all-purpose readable spreadsheet files, Excel Writer is a fine tool. I try to improve it a little bit (colored text has been done already) and also try to remove some issues in the original library (one is, that it creates a wrong header because of a version code 10 instead of 16)...

For all interested, here's a program which 'debugs' the streams of a file in Excel 2.x format. It decodes most of needed ID's and could be useful for analyzing your spreadsheet files.

Code: Select all

Procedure XlsInit()

	; BIFF 2.1 Decoding - Version 1.1 - Michael Vogel
	
	EnableExplicit
	
	Global XlsStream.s
	Global XlsStreamID.w
	Global XlsStreamLen.w
	Global XlsFunctionCount

	Global XlsShow
	Global XlsLine.s="--------------------------------------------"

	#XlsFile=0
	#Nil=-1

	Enumeration
		#XlsOpenOk
		#XlsOpenErrorFileNotFound
		#XlsOpenErrorFileLocked
		#XlsOpenErrorIllegalFormat
		#XlsOpenErrorIllegalType
		;
		#XlsReadStreamOk
		#XlsReadStreamError
	EndEnumeration


	#XlsIDDimension=		$00
	#XlsIDNumber=		$03
	#XlsIDLabel=			$04

	#XlsIDRow=			$08

	#XlsIDBof=			$09
	#XlsBof_Version2=	$02
	#XlsBof_Version2_1=	$07
	#XlsBof_Sheet=		$10

	#XlsIDEof=			$0A
	#XlsIDIndex=			$0B
	#XlsIDCalccount=		$0C

	#XlsIDCalcmode=		$0D
	#XlsCalcmodeAuto=	-$01;
	#XlsCalcmodeManual=$00
	#XlsCalcmodeAllAuto=	$01;	default

	#XLSIDPrecision=		$0E
	#XLSPrecisionDisplay=$00
	#XLSPrecisionReal=	$01;	default

	#XLSIDRefmode=		$0F
	#XLSRefmodeRC=		$00
	#XLSRefmodeA1=		$01;	default

	#XlsIDDelta=			$10
	#XlsIDIteration=		$11
	#XlsIDProtect=		$12
	#XlsIDPassword=		$13
	#XlsIDHeader=		$14
	#XlsIDFooter=			$15
	#XlsIDDefinedName=	$18
	#XlsIDWinProtect=	$19
	#XlsIDSelection=		$1D
	#XlsIDFormat=		$1E
	#XlsIDBuiltinFmtCnt=	$1F

	#XlsIDDateMode=		$22
	#XlsDateMode1899=	$00
	#XlsDateMode1904=	$01

	#XlsIDColwidth=		$24
	#XlsIDDefRowHeight=	$25
	#XlsIDLeftMargin=		$26
	#XlsIDRightMargin=	$27
	#XlsIDTopMargin=		$28
	#XlsIDBottomMargin=	$29
	#XlsIDPrintHeaders=	$2A
	#XlsIDPrintGridlines=	$2B
	#XlsIDFont=			$31
	#XlsIDWindow1=		$3D
	#XlsIDWindow2=		$3E
	#XlsIDBackup=		$40

	#XlsIDCodepage=		$42
	#XlsCodepageAscii=	$016F
	#XlsCodepageApple=	$8000
	#XlsCodepageLatin=	$8001

	#XlsXF=				$43
	#XlsIDFontColor=		$45
	#XlsIDDefColwidth=	$55

EndProcedure

Procedure XlsReadWord(offset)

	ProcedureReturn PeekW(@XlsStream+offset)

EndProcedure
Procedure XlsReadStream()

	XlsStreamID=ReadWord(#XlsFile)
	XlsStreamLen=ReadWord(#XlsFile)

	XlsStream=Space(XlsStreamLen)
	If ReadData(#XlsFile,@XlsStream,XlsStreamLen)-XlsStreamLen
		ProcedureReturn #XlsReadStreamError
	EndIf

	ProcedureReturn #XlsReadStreamOk

EndProcedure
Procedure XlsOpen(file.s)

	If FileSize(file)>33
		If OpenFile(#XlsFile,file)
			If XlsReadStream()=#XlsReadStreamOk
				If XlsStreamID=9 And XlsStreamLen=4
					If (XlsReadWord(0)=#XlsBof_Version2) Or (XlsReadWord(0)=#XlsBof_Version2_1)
						If XlsReadWord(2)=#XlsBof_Sheet
							ProcedureReturn #XlsOpenOk
						Else
							ProcedureReturn #XlsOpenErrorIllegalType
						EndIf
					EndIf
				EndIf
				ProcedureReturn #XlsOpenErrorIllegalFormat
			Else
				ProcedureReturn #XlsOpenErrorIllegalFormat
			EndIf
		Else
			ProcedureReturn #XlsOpenErrorFileLocked
		EndIf
	Else
		ProcedureReturn #XlsOpenErrorFileNotFound
	EndIf

EndProcedure

Macro HexByte(x)

	RSet(Hex((x)),2,"0")

EndMacro
Macro HexWord(x)

	RSet(Hex((x)),4,"0")

EndMacro
Macro XlsByte(x)

	(PeekA(@XlsStream+(x)))

EndMacro
Macro XlsWord(x)

	(PeekW(@XlsStream+(x))&$FFFF)

EndMacro
Macro XlsLong(x)

	(PeekL(@XlsStream+(x)))

EndMacro

Procedure.s XlsShowStream()

	Protected c,n
	Protected a.s,s.s

	s=HexWord(XlsStreamID)+" ["+HexByte(XlsStreamLen)+"]:"

	While n<XlsStreamLen
		c=PeekA(@XlsStream+n)
		s+" "+HexByte(c)
		If c<33 Or c>126
			c='.'
		EndIf
		a+Chr(c)
		n+1
	Wend

	ProcedureReturn s+" - "+a

EndProcedure
Procedure.s XlsShowBinary(FlagName.s,value,description.s)

	Protected i,n,z,b1,b2
	Protected b.s,f.s,s.s

	s="+"+FlagName+": "
	n=CountString(description,",")+1

	i=n
	While i
		f=StringField(description,i,",")
		z=FindString(f,"=")
		If z
			b=Left(f,z-1)
			f=Mid(f,z+1)
		Else
			b=f
			f=""
		EndIf

		z=FindString(b,"-")
		b1=Val(b)
		If z
			b2=Val(Mid(b,z+1))
			If b1>b2
				Swap b1,b2
			EndIf
		Else
			b2=b1
		EndIf

		b2=b2-b1+1
		b1=(value>>b1) & ((1<<b2)-1)

		If i<>n
			s+","
		EndIf

		s+" "+Str(b1)+"("+RSet(Bin(b1),b2,"0")+")="+f

		i-1

	Wend

	ProcedureReturn s

EndProcedure
Procedure.s XlsShowValue(offset,text.s,prefix.s=",")

	Protected n

	If offset<>#Nil

		Select PeekA(@text)
		Case 'w';	Word (2 Byte, decimal output)
			ProcedureReturn prefix+" "+Str(XlsWord(offset))+"="+Mid(text,2)
		Case 'x';	Word (2 Byte, hex output)
			ProcedureReturn prefix+" "+HexWord(XlsWord(offset))+"="+Mid(text,2)
		Case 'i';	Long (4 Byte, decimal output)
			ProcedureReturn prefix+" "+Str(XlsLong(offset))+"="+Mid(text,2)
		Case 'f';	Float (8 Byte)
			ProcedureReturn prefix+" "+StrD(PeekD(@XlsStream+offset))+"="+Mid(text,2)
		Case 'b';	Binary (1 Byte)
			ProcedureReturn prefix+" x"+HexByte(PeekA(@XlsStream+offset))+"="+Mid(text,2)
			;ProcedureReturn prefix+" b"+RSet(Bin(PeekA(@XlsStream+offset)),8,"0")+"="+Mid(text,2)
		Case 's';	String (var)
			n=PeekA(@XlsStream+offset)
			ProcedureReturn prefix+" '"+PeekS(@XlsStream+offset+1,n)+"'="+Mid(text,2)
		Case '*';	String (var)
			n=PeekA(@text+1)-1
			ProcedureReturn prefix+" '"+PeekS(@XlsStream+offset,n)+"'="+Mid(text,3)
		Default;	unknown
			ProcedureReturn prefix+" <"+Left(text,1)+"?>"
		EndSelect
	EndIf

	ProcedureReturn ""

EndProcedure
Procedure.s XlsShowValues(IDName.s,o1,v1.s,o2=#Nil,v2.s="",o3=#Nil,v3.s="",o4=#Nil,v4.s="",o5=#Nil,v5.s="",o6=#Nil,v6.s="")

	Protected s.s

	s=IDName

	s+XlsShowValue(o1,v1,"")
	s+XlsShowValue(o2,v2)
	s+XlsShowValue(o3,v3)
	s+XlsShowValue(o4,v4)
	s+XlsShowValue(o5,v5)
	s+XlsShowValue(o6,v6)

	ProcedureReturn s

EndProcedure

Procedure Show(s.s)
	
	If XlsShow
		Debug s
	EndIf
	
EndProcedure
Procedure Main(file.s)

	Protected s.s
	Protected i,n
	Protected flen,slen
	Protected frow,lrow
	Protected quit
	Protected NotShown

	XlsInit()
	
	If XlsOpen(file)=#XlsOpenOk

		Repeat
			
			XlsShow=#True
			
			n=XlsReadStream()
			If n=#XlsReadStreamOk

				Select XlsStreamID

				Case #XlsIDDimension
					Show(XlsShowValues("DIMENSION",0,"wIndex first Row",2,"wIndex last Row",4,"wIndex first Column",6,"wIndex last Column"))
				Case #XlsIDRow
					Show(XlsShowValues("ROW",0,"wRow",2,"wIndex first Column",4,"wIndex last Column",6,"wRow Height",10,"bDefaults",11,"wRelative Offset"))
				Case #XlsIDDefRowHeight
					Show(XlsShowValues("DEFROWHEIGHT",0,"wRow Height (1/20 point)"))
				Case #XlsIDColwidth
					Show(XlsShowValues("COLWIDTH",0,"bIndex first Column",1,"bIndex last Column",2,"wColumn Width (1/256)"))
				Case #XlsIDDefColwidth
					Show(XlsShowValues("DEFCOLWIDTH",0,"wColumn Width (chars)"))
				Case #XlsIDIndex
					frow=XlsWord(4)
					lrow=XlsWord(6)
					n=((lrow-frow-1)>>5)+1
					Show(XlsShowValues("INDEX",0,"iDefinedName Record Position",4,"wFirst Used Row Index",6,"wLast Used Row Index (+1)")+" -> "+Str(n)+" Row Record Entries")
					For i=1 To n
						Show(XlsShowValues("INDEX ("+Str(i)+") ",4+4*i,"iRow Record Stream Position"))
					Next i

				Case #XlsIDNumber
					Show(XlsShowValues("NUMBER",0,"wRow",2,"wColumn",4,"bCell/XF",5,"bFormat",6,"bAlignment",7,"fValue"))
					Show(XlsShowBinary("Cell/XF",XlsByte(4),"5-0=XF Index,6=Cell locked,7=Formula Hidden"))
					Show(XlsShowBinary("Format",XlsByte(5),"5-0=Format Record Index,7-6=Font Record Index"))
					Show(XlsShowBinary("Alignment",XlsByte(6),"2-0=Horizontal Alignment,3=Left Border,4=Right Border,5=Top Border,6=Bottom Border,7=Shaded Background"))

				Case #XlsIDLabel
					Show(XlsShowValues("LABEL",0,"wRow",2,"wColumn",4,"bCell/XF",5,"bFormat",6,"bAlignment",7,"sValue"))
					Show(XlsShowBinary("Cell/XF",XlsByte(4),"5-0=XF Index,6=Cell locked,7=Formula Hidden"))
					Show(XlsShowBinary("Format",XlsByte(5),"5-0=Format Record Index,7-6=Font Record Index"))
					Show(XlsShowBinary("Alignment",XlsByte(6),"2-0=Horizontal Alignment,3=Left Border,4=Right Border,5=Top Border,6=Bottom Border,7=Shaded Background"))
					
				Case #XlsIDBuiltinFmtCnt
					Show(XlsShowValues("BUILTINFMTCOUNT",0,"wNumber of following Format Records"))
				Case #XlsIDFormat
					XlsFunctionCount+1
					Show(XlsShowValues("FORMAT (#"+Str(XlsFunctionCount)+")",0,"sNumber format"))
				Case #XlsIDFont
					Show(XlsShowValues("FONT",0,"wHeight",2,"xFlags",4,"sName"))
				Case #XlsIDFontColor
					Show(XlsShowValues("FONTCOLOR",0,"xColor Index"))
				Case #XlsXF
					Show(XlsShowValues("XF",0,"bFont Index",1,"bn/a",2,"bNumber Format",3,"bAlignment"))
					Show(XlsShowBinary("Number Format",XlsByte(2),"5-0=Format Record Index,7-6=Font Record Index"))
					Show(XlsShowBinary("Alignment",XlsByte(3),"2-0=Horizontal Alignment,3=Left Border,4=Right Border,5=Top Border,6=Bottom Border,7=Shaded Background"))

				Case #XlsIDDefinedName
					slen=XlsByte(3)
					flen=XlsByte(4)
					Show(XlsShowValues("DEFINEDNAME (1)",0,"bMacro/Function",1,"bFunction/Command Macro",2,"bKeyboard Shortcut",3,"bName Length"))
					Show(XlsShowValues("DEFINEDNAME (2)",4,"bFormula Size",5,"*"+Chr(slen+1)+"Name",slen+5,"*"+Chr(flen+1)+"Formula Data",5+slen+flen,"bFormula Size (Dup)"))
				Case #XlsIDProtect
					Show(XlsShowValues("PROTECT",0,"wProtected Flag"))
				Case #XlsIDWindow1,#XlsIDWindow2
					n=XlsStreamID-#XlsIDWindow1+1
					Show(XlsShowValues("WINDOW"+Str(n),0,"?????"))
					
				Case #XlsIDPrintHeaders
					Show(XlsShowValues("PRINTHEADERS",0,"wPrint Headers-Flag (0=no, 1=yes)"))
				Case #XlsIDPrintGridlines
					Show(XlsShowValues("PRINTGRIDLINES",0,"wPrint Grid Lines-Flag (0=no, 1=yes)"))
				Case #XlsIDLeftMargin To #XlsIDBottomMargin
					s=StringField("Left|Right|Top|Bottom",XlsStreamID-#XlsIDLeftMargin+1,"|")
					Show(XlsShowValues(UCase(s)+"MARGIN",0,"f"+s+" Page Margin (inch)"))
				Case #XlsIDHeader
					Show(XlsShowValues("HEADER",0,"sHeader String (non-empty)"))
				Case #XlsIDFooter
					Show(XlsShowValues("FOOTER",0,"sFooter String (non-empty)"))
					
				Case #XlsIDCodepage
					Show(XlsShowValues("CODEPAGE",0,"wCodepage"))
				Case #XlsIDCalccount
					Show(XlsShowValues("CALCCOUNT",0,"wmax. Iterations"))
				Case #XlsIDCalcmode
					Show(XlsShowValues("CALCMODE",0,"wFunction Calculation Mode"))
				Case #XLSIDPrecision
					Show(XlsShowValues("PRECISION",0,"wCalculation Setting"))
				Case #XLSIDRefmode
					Show(XlsShowValues("REFMODE",0,"wFormulas Reference Mode"))
				Case #XlsIDDelta
					Show(XlsShowValues("DELTA",0,"fMax. Change in Iteration"))
				Case #XlsIDIteration
					Show(XlsShowValues("ITERATION",0,"wIteration-Flag"))
				Case #XlsIDDateMode
					Show(XlsShowValues("DATEMODE",0,"wBase Date"))
				Case #XlsIDWinProtect
					Show(XlsShowValues("WINDOWPROTECT",0,"wWindow settings protected (0=no, 1=yes)"))
				Case #XlsIDPassword
					Show(XlsShowValues("PASSWORD",0,"wPassword Hash Value"))
					
				Case #XlsIDSelection
					Show(XlsShowValues("SELECTION",0,"?????"))
				Case #XlsIDBackup
					Show(XlsShowValues("BACKUP",0,"wCreate Backup File (0=no, 1=yes)"))

				Case #XlsIDEof
					XlsShow=#False
					quit=#True

				Default
					XlsShow=1
					;XlsShow=#False;	supress unknown streams..

				EndSelect

				If XlsShow
					Show(XlsShowStream())
					If NotShown
						Show(XlsLine+" ("+Str(NotShown)+" skipped) "+XlsLine)
					Else
						Show(XlsLine+"---------------------"+XlsLine)
					EndIf
					NotShown=0
				Else
					NotShown+1
				EndIf
				
			Else
				Show("STREAM ERROR "+Str(n))
				quit=#True
				
			EndIf
		Until quit
		
	Else
		
		Show("FILE OPEN ERROR")
		
	EndIf

EndProcedure

Main("Test21.xls")
ebs
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Apr 25, 2003 11:08 pm

Re: Excel Writer improvements

Post by ebs »

Hi Michael,

I'm trying to use your extensions to the "ExcelWriter" code. When I try to compile your code
(in the first post), I get an error saying that the procedure "Ipf_WriteToFile()" is undefined.

I don't see it anywhere in your code, or in the original "ExcelWriter.pbi" file.
Can you tell me where this code is supposed to be?

Thanks,
Eric
User avatar
Michael Vogel
Addict
Addict
Posts: 2823
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Excel Writer improvements

Post by Michael Vogel »

ebs wrote:Hi Michael,

I'm trying to use your extensions to the "ExcelWriter" code. When I try to compile your code
(in the first post), I get an error saying that the procedure "Ipf_WriteToFile()" is undefined.

I don't see it anywhere in your code, or in the original "ExcelWriter.pbi" file.
Can you tell me where this code is supposed to be?

Thanks,
Eric
See here:
http://www.purebasic.fr/english/viewtop ... 9&p=320716
User avatar
Michael Vogel
Addict
Addict
Posts: 2823
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Excel Writer improvements

Post by Michael Vogel »

Just found a c++ library which is able to do quite a lot more for reading/writing excel files than the snippets above.
Post Reply