Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel Sheet Formatting
Message
From
06/03/2006 13:19:45
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01087027
Message ID:
01101767
Views:
13
>>Borislav, Tariq,
>>Thanks to Sergey, you can surpres 0s this way
>>
>>.NumberFormat = "###,###,###"
>>* Or condtional formatting
>>.NumberFormat = "#[=0];###,###,###.00"
>>
>>
>
>How can I apply this format to the range, e.g. I don't want the format to be applied to the first 3 rows where I put my column titles. Here is my current code:
>
>
>function DBFToExcel
>lparameters tcXLSFileName, taHeader_Info
>* This function assumes, that the output table (cursor) is currently opened
>*-- Generate output to XLS File
>
>local loExcel, lnI, loSheet, lnK, lcTempFile, lcError
>*lcTempFile = addbs(sys(2023)) + "TempXLS" + sys(3) + ".XLS"
>lcError = ""
>
>#define xlShiftDown -4121
>#define xlShiftToLeft -4159
>#define xlShiftToRight -4161
>#define xlShiftUp -4162
>
>* Line styles
>#Define xlContinuous 1
>#Define xlDash -4115
>#Define xlDashDot 4
>#Define xlDashDotDot 5
>#Define xlDot -4118
>#Define xlDouble -4119
>#Define xlSlantDashDot 13
>#Define xlLineStyleNone -4142
>
>* Weight
>#Define xlHairline 1
>#Define xlMedium -4138
>#Define xlThick 4
>#Define xlThin 2
>
>*-- Add Header into XLS File
>try
>	copy to (m.tcXLSFileName) TYPE XL5
>*-- Create Ole Automation with Excel
>	loExcel=createobject("Excel.Application")
>*-- Open XLS File
>	loExcel.application.WorkBooks.open(m.tcXLSFileName)
>	for lnI = 1 to loExcel.application.application.WorkBooks(1).Sheets.count
>*-- Select individual sheet from open XLS File
>		loSheet = loExcel.application.application.WorkBooks(1).Sheets(m.lnI)
>*		loSheet.select
>
>** Delete the column headers from Excel (first row)
>		loSheet.rows("1").delete(xlShiftDown)
>		loSheet.rows("1:3").insert(xlShiftDown)
>		
>		With loSheet.Range("1:2").Font
>		*  .Color = Rgb(255,0,0)
>		  .Size  = 11
>		  .Bold  = .T.
>		  .Name = 'Tahoma'
> 		Endwith
>		
>*!*			With loSheet.Range("1:2").Borders
>*!*			  .Weight = xlMedium
>*!*			  .LineStyle = xlContinuous
>*!*			 Endwith
>
>		for lnK = 1 to alen(taHeader_Info,1)
>			loSheet.Cells(1,m.lnK).value = taHeader_Info[m.lnK,1]
>			loSheet.Cells(2,m.lnK).value = taHeader_Info[m.lnK,2]
>			
>			if !empty(taHeader_Info[m.lnK,3]) && There is format information
>				*loSheet.columns[m.lnK].select
>				loSheet.columns[m.lnK].NumberFormat = taHeader_Info[m.lnK,3]
>			endif
>			if !empty(taHeader_Info[m.lnK,4]) && There is Column Width
>				loSheet.columns[m.lnK].select
>				loSheet.columns[m.lnK].ColumnWidth = taHeader_Info[m.lnK,4]
>			endif
>		next
>	next
>	loExcel.application.WorkBooks(1).save()
>
>catch to loError
>	lcError = Log_Error(m.loError)
>finally
>	if vartype(m.loExcel) = 'O'
>		loExcel.quit
>	endif
>endtry
>if not empty(m.lcError)
>	=ErrorMsg(m.lcError)
>endif
>return m.lcError
>endfunc
>
loRange = loSheet.UsedRange.Offset(3,0)
loRange.columns[m.lnK].NumberFormat = taHeader_Info[m.lnK,3]

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform