From data base to Excel: formatting data.... HELP

mercoledì 06 febbraio 2008 - 21.27

tappat Profilo | Newbie

Voglio creare un file di excel con un'applicazione Web (Visual studio 2005) estraendo i dato da una tabella di SQLserver2005.
Sul server non c'è l'applicazione excel quindi niente OXPPIA's.
Il file viene creato dinamicamente sul server , e, per ora, salvato sempre sul server. Poi, l'end user, sceglierè da una lista quale scaricarsi sul Pc.
Sono riuscita a creare il file ma, purtroppo, non riesco a formattare la colonna "importo", e sarebbe il minimo, ma ottengo un foglio .xls inutilizzabile.
Sul server le cifre sono numeric(18,2). esempio: 1234,99 -34567,11
Il file che ottengo ha una colonna Importo che oltre a non essere formattata (il risultato è "generale", allineam. a sx, 1234,99 -34567,11) non è nemmeno formattabile aperto con Excel!!! Nemmeno manualmente si riesce a formattarlo in numerico! non è numerico e quindi non fai nemmeno una misera somma...
Quello che vorrei ottenere è 1.234,99 -34.567,11 oltrechè una colonna di importi veri sui quali poter lavorare!
Il template che ho usato per creare il testo HTM (che è compatibile 100% con XL) riporta correttamente la formattazione della <TD> che contiene la pseudo cifra
(.xl26
{mso-style-parent:style0;
mso-number-format:Standard;}
Se apro in excel il file ottenuto ne leggo il codice HTM, trovo regolarmente impostata la formattazione numerica standard ma il dato resta non formattato.

qualcuno mi può aiutare?
Grazie!

Tappat (code is following)

CODE:
Sub creaXLtuttiConti()

Dim a
Dim fso = CreateObject("Scripting.FileSystemObject")
Dim pathTemplate, pathTEMP
Dim leggiFile As String, tabellaConti As String

nomeConto = "12345"
anno = "2007"

......
pathTemplate = Server.MapPath("../XLtemplates/TemplOneri.txt")
pathTEMP = Server.MapPath("../Temp/" & nomeDir & "/" & nomeConto & "_" & anno & ".xls")

queryString = "SELECT ......"

Dim cmd1 As New SqlCommand(queryString, cnSql)
Dim reader As SqlDataReader = cmd1.ExecuteReader()
Dim numRec As Integer = 0
Dim numFile As Integer = 1

If reader.HasRows Then
Do While reader.Read()
tabellaConti = tabellaConti & "<tr height=17 style='height:12.75pt'>"
tabellaConti = tabellaConti & "<td height=17 class=xl25 style='height:12.75pt'>" & reader.GetString(0) & "</td>"
tabellaConti = tabellaConti & "<td class=xl25>" & reader.GetString(1) & "</td>"
tabellaConti = tabellaConti & "<td class=xl25>" & reader.GetString(2) & "</td>"
tabellaConti = tabellaConti & "<td class=xl25>" & reader.GetValue(3) & "</td>"
tabellaConti = tabellaConti & "<td style=xl26>" & reader.GetValue(4) & "</td>"

numRec = numRec + 1
If numRec >= 65000 Then
pathTEMP = Server.MapPath("../Temp/" & nomeDir & "/" & nomeConto & "_0" & numFile & "_" & anno & ".xls")
a = fso.OpenTextFile(pathTemplate)
leggiFile = a.readall

a = fso.CreateTextFile(pathTEMP, True)
leggiFile = Replace(leggiFile, "[datiMonitoraggio]", tabellaConti)
a.write(leggiFile)
a.close()

numRec = 0
numFile = numFile + 1
tabellaConti = ""
End If

Loop
End If

reader.Close()
cmd1.Dispose()

a = fso.OpenTextFile(pathTemplate)
leggiFile = a.readall

a = fso.CreateTextFile(pathTEMP, True)
leggiFile = Replace(leggiFile, "[datiMonitoraggio]", tabellaConti)
a.write(leggiFile)
a.close()

End Sub




FILE: templOmeri.txt

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
......................
<style>
<!--table
{mso-displayed-decimal-separator:"\,";
mso-displayed-thousand-separator:"\.";}
@page
{mso-header-data:"&LT\.A\.P\.P\. Oneri";
mso-footer-data:&R&P;
margin:.98in .79in .98in .79in;
mso-header-margin:.51in;
mso-footer-margin:.51in;
mso-horizontal-page-align:center;}
.......
td
{mso-style-parent:style0;
padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Arial;
mso-generic-font-family:auto;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
...........
.xl26
{mso-style-parent:style0;
mso-number-format:Standard;}

<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Foglio1</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>240</x:DefaultRowHeight>
<x:Print>
<x:ValidPrinterInfo/>
<x:PaperSizeIndex>9</x:PaperSizeIndex>
<x:VerticalResolution>0</x:VerticalResolution>
<x:Gridlines/>
</x:Print>
<x:PageBreakZoom>60</x:PageBreakZoom>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveRow>1</x:ActiveRow>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Foglio2</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>240</x:DefaultRowHeight>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Foglio3</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>240</x:DefaultRowHeight>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>8445</x:WindowHeight>
<x:WindowWidth>13275</x:WindowWidth>
<x:WindowTopX>240</x:WindowTopX>
<x:WindowTopY>30</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
<x:ExcelName>
<x:Name>Print_Titles</x:Name>
<x:SheetIndex>1</x:SheetIndex>
<x:Formula>=Foglio1!$1:$1</x:Formula>
</x:ExcelName>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=654 style='border-collapse:
collapse;table-layout:fixed;width:491pt'>
<col class=xl24 width=64 style='width:48pt'>
<col class=xl25 width=97 style='mso-width-source:userset;mso-width-alt:3547;
width:73pt'>
<col class=xl25 width=248 style='mso-width-source:userset;mso-width-alt:9069;
width:186pt'>
<col class=xl24 width=76 style='mso-width-source:userset;mso-width-alt:2779;
width:57pt'>
<col class=xl26 width=169 style='mso-width-source:userset;mso-width-alt:6180;
width:127pt'>
......

</table>


Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5