Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
COPYing numeric data to an XLS
Message
De
27/07/2009 12:17:09
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Divers
Thread ID:
01413826
Message ID:
01414778
Vues:
50
>Hi Yossi,
>
>>Although I when I look at the format of each cell in Excel, they are all 'General', so whet do we accomplish with this?
>
>No, that's two different things. A cell has a format and a type. The type determines the automatic formatting of a cell. In my sample this type is set correctly, which is why the number line is right aligned, all other lines are left aligned. The format dialog will always show "generic", no matter what data type you have, unless you specify a cell format. The following modified sample specifies the default format for numbers explicitly:
>
>Create Cursor Sample (cData C(30))
>Insert into Sample values("Some text")
>Insert into Sample values("1.23")
>Insert into Sample values("999-444")
>Insert into Sample values("Some more text")
>StrToFile(ExportToExcel(),"Sample.xls")
>
>
>*========================================================================================
>* Export the current cursor to Excel (XMLSS format)
>*========================================================================================
>Procedure ExportToExcel
>
>	*--------------------------------------------------------------------------------------
>	* Setup environment
>	*--------------------------------------------------------------------------------------
>	Local lcPoint
>	lcPoint = Set("Point")
>	Set Point To "."
>
>	*--------------------------------------------------------------------------------------
>	* Create a header
>	*--------------------------------------------------------------------------------------
>	Local lcHeader
>	Text to m.lcHeader NoShow
>		<?xml version="1.0"?>
>		<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
>		 xmlns:x="urn:schemas-microsoft-com:office:excel"
>		 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
>		  <Styles>
>		    <Style ss:ID="numformat">
>		      <NumberFormat ss:Format="Fixed"/>
>		    </Style>
>		  </Styles>
>		  <Worksheet ss:Name="Sheet1">
>		    <Table>
>	EndText 
>		
>	*--------------------------------------------------------------------------------------
>	* Assemble a string with all rows
>	*--------------------------------------------------------------------------------------
>	Local lcData, lcRow, lnField, luValue
>	lcData = ""
>	Scan
>		lcRow = "<Row>"
>		For lnField = 1 to Fcount()
>			luValue = Evaluate(Field(m.lnField))
>			Do case
>			Case Vartype(m.luValue) == "C"
>				luValue = Alltrim(Nvl(m.luValue,""))
>				If Transform(Val(m.luValue)) == m.luValue
>					lcRow = m.lcRow + ;
>						[<Cell ss:StyleID="numformat"><Data ss:Type="Number">] + m.luValue+ [</Data></Cell>]
>				Else
>					lcRow = m.lcRow + ;
>						[<Cell><Data ss:Type="String">] + STRCONV(m.luValue,9)+ [</Data></Cell>]
>				EndIf 
>			Case Vartype(m.luValue) == "N"
>				lcRow = m.lcRow + ;
>					[<Cell ss:StyleID="numformat"><Data ss:Type="Number">] + Transform(Nvl(m.luValue,0)) + ;
>					[</Data></Cell>]
>			Otherwise 
>				Assert .F. message "Type not supported"
>			EndCase 
>		EndFor 
>		lcRow = m.lcRow + "</Row>"
>		lcData = m.lcData + m.lcRow
>	EndScan 
>	
>	*--------------------------------------------------------------------------------------
>	* Create the footer
>	*--------------------------------------------------------------------------------------
>	Local lcFooter
>	Text to m.lcFooter noshow 
>		    </Table>
>		  </Worksheet>
>		</Workbook>
>	EndText 
>	
>	*--------------------------------------------------------------------------------------
>	* Restore environment
>	*--------------------------------------------------------------------------------------
>	Set Point To m.lcPoint
>
>Return m.lcHeader + m.lcData + m.lcFooter
>
Thanks!

Where is this stuff documented?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform