Questo script per genera documenti .doc compatibili con MS Word 2000, Word XP e Word 2003, usando un nome random per il file .doc che verrà salvato sul server remoto.
Al termine della procedura si viene reindirizzati sul documento per il download o per l'apertura dello stesso.
Punto forte di questo script è la possibilità di inserire interruzioni di pagina nei documenti (codice
), senza contare la forte personalizzazione tramite i parametri riconosciuti da Word.
Nella scrittura del codice, è importante mantenere una riga di spazio tra i vari tag del documento.
<% 'Crea il nome del file Randomize Do Until len(nomefile) = 10 numero = Int((9 * Rnd) + 1) nomefile = nomefile & numero Loop nomefileS = "DOC"& nomefile nomefile = "DOC"& nomefile &".doc" 'Opzioni documento autore="Stefano Pessina" azienda="TNTDeveloping.com" 'Genera il testo del file testo="MIME-Version: 1.0"& VbCrLf &_ "Content-Location: file:///C:/0C6649EF/"& nomefileS &".htm"& VbCrLf &_ "Content-Transfer-Encoding: quoted-printable"& VbCrLf &_ "Content-Type: text/html; charset=""us-ascii"""& VbCrLf & VbCrLf &_ "<html xmlns:o=3D""urn:schemas-microsoft-com:office:office"""& VbCrLf &_ "xmlns:w=3D""urn:schemas-microsoft-com:office:word"""& VbCrLf &_ "xmlns=3D""http://www.w3.org/TR/REC-html40"">"& VbCrLf & VbCrLf &_ "<head>"& VbCrLf &_ "<meta http-equiv=3DContent-Type content=3D""text/html; charset=3Dus-ascii"">"& VbCrLf &_ "<meta name=3DProgId content=3DWord.Document>"& VbCrLf &_ "<meta name=3DGenerator content=3D""Microsoft Word 11"">"& VbCrLf &_ "<meta name=3DOriginator content=3D""Microsoft Word 11"">"& VbCrLf &_ "<link rel=3DFile-List href=3D"""& nomefileS &"_file/filelist.xml"">"& VbCrLf &_ "<title></title>"& VbCrLf &_ "<!--[if gte mso 9]><xml>"& VbCrLf &_ " <o:DocumentProperties>"& VbCrLf &_ " <o:Author>"& autore &"</o:Author>"& VbCrLf &_ " <o:Template>Normal</o:Template>"& VbCrLf &_ " <o:LastAuthor>" & autore & "</o:LastAuthor>"& VbCrLf &_ " <o:Revision>1</o:Revision>"& VbCrLf &_ " <o:TotalTime>1</o:TotalTime>"& VbCrLf &_ " <o:Created>2004-01-22T14:31:00Z</o:Created>"& VbCrLf &_ " <o:LastSaved>2004-01-22T14:33:00Z</o:LastSaved>"& VbCrLf &_ " <o:Pages>1</o:Pages>"& VbCrLf &_ " <o:Words>4</o:Words>"& VbCrLf &_ " <o:Characters>24</o:Characters>"& VbCrLf &_ " <o:Company>"& azienda &"</o:Company>"& VbCrLf &_ " <o:Lines>1</o:Lines>"& VbCrLf &_ " <o:Paragraphs>1</o:Paragraphs>"& VbCrLf &_ " <o:CharactersWithSpaces>27</o:CharactersWithSpaces>"& VbCrLf &_ " <o:Version>11.5703</o:Version>"& VbCrLf &_ "</o:DocumentProperties>"& VbCrLf &_ "</xml><![endif]--><!--[if gte mso 9]><xml>"& VbCrLf &_ "<w:WordDocument>"& VbCrLf &_ " <w:View>Print</w:View>"& VbCrLf &_ " <w:Zoom>90</w:Zoom>"& VbCrLf &_ " <w:SpellingState>Clean</w:SpellingState>"& VbCrLf &_ " <w:GrammarState>Clean</w:GrammarState>"& VbCrLf &_ " <w:HyphenationZone>14</w:HyphenationZone>"& VbCrLf &_ " <w:ValidateAgainstSchemas/>"& VbCrLf &_ " <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>"& VbCrLf &_ " <w:IgnoreMixedContent>false</w:IgnoreMixedContent>"& VbCrLf &_ " <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>"& VbCrLf &_ " <w:Compatibility>"& VbCrLf &_ " <w:BreakWrappedTables/>"& VbCrLf &_ " <w:SnapToGridInCell/>"& VbCrLf &_ " <w:WrapTextWithPunct/>"& VbCrLf &_ " <w:UseAsianBreakRules/>"& VbCrLf &_ " <w:UseWord2002TableStyleRules/>"& VbCrLf &_ " </w:Compatibility>"& VbCrLf &_ " <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>"& VbCrLf &_ " </w:WordDocument>"& VbCrLf &_ "</xml><![endif]--><!--[if gte mso 9]><xml>"& VbCrLf &_ "<w:LatentStyles DefLockedState=3D""false"" LatentStyleCount=3D""156"">"& VbCrLf &_ "</w:LatentStyles>"& VbCrLf &_ "</xml><![endif]-->"& VbCrLf &_ "<style>"& VbCrLf &_ "<!--"& VbCrLf &_ " /* Style Definitions */"& VbCrLf &_ " p.MsoNormal, li.MsoNormal, div.MsoNormal"& VbCrLf &_ " {mso-style-parent:"""";"& VbCrLf &_ " margin:0cm;"& VbCrLf &_ " margin-bottom:.0001pt;"& VbCrLf &_ " mso-pagination:widow-orphan;"& VbCrLf &_ " font-size:12.0pt;"& VbCrLf &_ " font-family:""Times New Roman"";"& VbCrLf &_ " mso-fareast-font-family:""Times New Roman"";}"& VbCrLf &_ "@page Section1"& VbCrLf &_ " {size:595.3pt 841.9pt;"& VbCrLf &_ " margin:70.85pt 2.0cm 2.0cm 2.0cm;"& VbCrLf &_ " mso-header-margin:35.4pt;"& VbCrLf &_ " mso-footer-margin:35.4pt;"& VbCrLf &_ " mso-paper-source:0;}"& VbCrLf &_ "div.Section1"& VbCrLf &_ " {page:Section1;}"& VbCrLf &_ "-->"& VbCrLf &_ "</style>"& VbCrLf &_ "<!--[if gte mso 10]>"& VbCrLf &_ "<style>"& VbCrLf &_ " /* Style Definitions */"& VbCrLf &_ " table.MsoNormalTable"& VbCrLf &_ " {mso-style-name:""Tabella normale"";"& VbCrLf &_ " mso-tstyle-rowband-size:0;"& VbCrLf &_ " mso-tstyle-colband-size:0;"& VbCrLf &_ " mso-style-noshow:yes;"& VbCrLf &_ " mso-style-parent:"""";"& VbCrLf &_ " mso-padding-alt:0cm 5.4pt 0cm 5.4pt;"& VbCrLf &_ " mso-para-margin:0cm;"& VbCrLf &_ " mso-para-margin-bottom:.0001pt;"& VbCrLf &_ " mso-pagination:widow-orphan;"& VbCrLf &_ " font-size:10.0pt;"& VbCrLf &_ " font-family:""Times New Roman"";"& VbCrLf &_ " mso-ansi-language:#0400;"& VbCrLf &_ " mso-fareast-language:#0400;"& VbCrLf &_ " mso-bidi-language:#0400;}"& VbCrLf &_ "table.MsoTableGrid"& VbCrLf &_ " {mso-style-name:""Griglia tabella"";"& VbCrLf &_ " mso-tstyle-rowband-size:0;"& VbCrLf &_ " mso-tstyle-colband-size:0;"& VbCrLf &_ " border:solid windowtext 1.0pt;"& VbCrLf &_ " mso-border-alt:solid windowtext .5pt;"& VbCrLf &_ " mso-padding-alt:0cm 5.4pt 0cm 5.4pt;"& VbCrLf &_ " mso-border-insideh:.5pt solid windowtext;"& VbCrLf &_ " mso-border-insidev:.5pt solid windowtext;"& VbCrLf &_ " mso-para-margin:0cm;"& VbCrLf &_ " mso-para-margin-bottom:.0001pt;"& VbCrLf &_ " mso-pagination:widow-orphan;"& VbCrLf &_ " font-size:10.0pt;"& VbCrLf &_ " font-family:""Times New Roman"";"& VbCrLf &_ " mso-ansi-language:#0400;"& VbCrLf &_ " mso-fareast-language:#0400;"& VbCrLf &_ " mso-bidi-language:#0400;}"& VbCrLf &_ "</style>"& VbCrLf &_ "<![endif]-->"& VbCrLf &_ "</head>"& VbCrLf & VbCrLf &_ "<body lang=3DIT style=3D'tab-interval:35.4pt'>"& VbCrLf & VbCrLf &_ "<div class=3DSection1>"& VbCrLf & VbCrLf &_ "<p class=3DMsoNormal>Pagina 1 - Testo di esempio</p>"& VbCrLf & VbCrLf &_ "<br clear=3Dall style=3D'page-break-before:always'>"& VbCrLf & VbCrLf &_ "<p class=3DMsoNormal>Pagina 2 - Data e ora: "& Now() &"</p>"& VbCrLf & VbCrLf &_ "<br clear=3Dall style=3D'page-break-before:always'>"& VbCrLf & VbCrLf &_ "<p class=3DMsoNormal>Pagina 3 - Percorso: "& Request.ServerVariables("PATH_INFO") &"</p>"& VbCrLf & VbCrLf &_ "</div>"& VbCrLf & VbCrLf &_ "</body>"& VbCrLf & VbCrLf &_ "</html>" 'Genera il file Set Documento=CreateObject("Scripting.FileSystemObject") Set Contenuto=Documento.CreateTextFile(Server.MapPath(nomefile),true) Contenuto.WriteLine(testo) Contenuto.Close 'Reindirizza al file per il download response.redirect nomefile %>
Commenti
Per inserire un commento, devi avere un account.
Fai il login e torna a questa pagina, oppure registrati alla nostra community.