Pagina 1 di 4 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 39

Discussione: Problema export excel

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    31

    Problema export excel

    Buongiorno a tutti,

    sto cercando di creare una piccola applicazione asp che mi consenta di andare a scrivere, nelle celle e fogli che desidero, all' interno di un file excel.

    Sui vari forum ho trovato di tutto per esportare dati in excel ma ho trovato poca roba in merito alla scrittura "guidata"...

    L' unico codice a mio avviso interessante è quello che vi posterò ma genera il seguente errore:

    Microsoft Excel error '800a03ec'

    Errore nel metodo SaveAs per la classe Workbook.

    /asp_format_style.asp, riga 138


    Qualcuno più esperto di me sa come risolvere questo problema? ecco il codice trovato, grazie mille per l' aiuto!


    <%Option Explicit%>
    <html>
    <head>
    <title>ShotDev.Com Tutorial</title>
    </head>
    <body>
    <%
    Dim xlApp,xlBook,xlSheet1,FileName
    Dim Fso,MyFile
    FileName = "MyXls/MyExcel.xls"

    '*** Create Excel.Application ***'
    Set xlApp = Server.CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add

    '*** Create Sheet 1 ***'
    xlBook.Worksheets(1).Name = "My Sheet1"
    xlBook.Worksheets(1).Select

    '*** Width & Height (A1:A1) ***'
    With xlApp.ActiveSheet.Range("A1:A1")
    .ColumnWidth = 40.0
    .RowHeight = 25.0
    End With

    '*** Write text to Row 1 Column 1 ***'
    With xlApp.ActiveSheet.Cells(1,1)
    .Value = "ShotDev.Com "
    .Font.Name = "Tahoma"
    .Font.Bold = True
    .VerticalAlignment = -4108 '*** Center Rows ***'
    .HorizontalAlignment = -4108 '*** Center Column ***'
    .Font.Size = 12
    End With

    '*** Width & Height (A1:B1) ***'
    With xlApp.ActiveSheet.Range("A1:B1")
    End With

    '*** Write text to Row 1 Column 2 ***'
    With xlApp.ActiveSheet.Cells(1,2)
    .Value = "Mr.Weerachai Nukitram "
    .Font.Name = "Tahoma"
    .Font.Size = 20
    End With

    '*** Width & Height (A2:A2) ***'
    With xlApp.ActiveSheet.Range("A2:A2")
    .BORDERS.Weight = 1 '*** Border ***'
    End With

    '*** Write text to Row 1 Column 2 ***'
    With xlApp.ActiveSheet.Cells(2,1)
    .Value = "I Love ShotDev.Com "
    .Font.Name = "Tahoma"
    .Font.Size = 10
    .HorizontalAlignment = 4
    End With

    '*** Width & Height (A33) ***'
    With xlApp.ActiveSheet.Range("A33")
    .BORDERS.Color = RGB(0, 0, 0) '*** Border Color ***'
    .BORDERS.Weight = 1 '*** Border ***'
    .MergeCells = True '*** Merge Cells ***'
    End With

    '*** Write text to Row 1 Column 2 ***'
    With xlApp.ActiveSheet.Cells(3,1)
    .Value = "I Love My Live"
    .Font.Name = "Tahoma"
    .Font.Size = 10
    .HorizontalAlignment = -4108
    .Interior.ColorIndex = 44 '*** Background Color ***'
    End With

    '*** Write text to Row 4 Column 5 ***'
    With xlApp.ActiveSheet.Cells(4,5)
    .Value = "My Life"
    .Font.Name = "Tahoma"
    .Font.Size = 10
    .Font.Italic = True
    .Font.ColorIndex = 4
    .EntireColumn.AutoFit '*** AutoFit Column ***'
    End With

    '*** Write text to Row 5 Column 5 ***'
    With xlApp.ActiveSheet.Cells(5,5)
    .Value = "My Life"
    .Font.Name = "Tahoma"
    .Font.Size = 10
    .Font.Italic = True
    .Font.ColorIndex = 4
    .HorizontalAlignment = -4152 '*** Text align Right ***'
    .EntireColumn.AutoFit '*** AutoFit Column ***'
    End With

    '*** Write text to Row 6 Column 1 ***'
    With xlApp.ActiveSheet.Cells(6,1)
    .Value = "Version 2010"
    .Font.Name = "Tahoma"
    .Font.Size = 10
    .Font.ColorIndex = 4
    .Characters(8, 12).Font.Bold = True
    End With


    '** SheetType
    'xlChart = -4109;
    'xlWorksheet = -4167;
    '** WBATemplate
    'xlWBATWorksheet = -4167;
    'xlWBATChart = -4109;
    '** Page Setup
    'xlPortrait = 1;
    'xlLandscape = 2;
    'xlPaperA4 = 9;
    '** Format Cells
    'xlBottom = -4107;
    'xlLeft = -4131;
    'xlRight = -4152;
    'xlTop = -4160;
    '** Text Alignment
    'xlHAlignCenter = -4108;
    'xlVAlignCenter = -4108;
    '** Cell Borders
    'xlThick = 4;
    'xlThin = 2;

    '*** If Files Already Exist Delete files ***'
    Set Fso = CreateObject("Scripting.FileSystemObject")
    If (Fso.FileExists(Server.MapPath(FileName))) Then
    Set MyFile = Fso.GetFile(Server.MapPath(FileName))
    MyFile.Delete
    End If

    '*** Save Excel ***'
    'xlBook.PrintOut 1 '*** Print to printer ***'
    xlBook.SaveAs Server.MapPath(FileName)
    xlApp.Application.Quit

    '*** Quit and Clear Object ***'
    Set xlSheet1 = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
    %>
    Excel Created Click here to Download.
    </body>
    </html>

  2. #2
    con questo codice sei obbligato ad avere Excel installato sul server: è una condizione che ti sta bene?

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    31
    Grazie intanto per la risposta.

    Le macchine che useranno questa applicazione non avranno office installato, proprio per questo dovrei crearla...

    Tieni presente che il codice postato prima non funziona neanche con excel installato..

  4. #4
    Originariamente inviato da lucamonc
    Le macchine che useranno questa applicazione non avranno office installato, proprio per questo dovrei crearla...
    quindi quel codice NON va bene (anche se Office andrebbe installato sul server, non sui client)

    cerca (anche qui su HTML.it) ci sono tanti esempi su come produrre un file Excel da ASP (senza passare da Office)

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    31
    Ho trovato anche questo codice, funziona ma non saprei come andare a scrivere nelle celle o fogli che desidero:

    <html>
    <title>CodeAve.com(Create Excel from User Input)</title>
    <body bgcolor="#FFFFFF">
    <%
    'Check to see if title has been entered or not
    u_title=request.form("u_title")
    if u_title = "" then
    %>

    <form method="POST" action="<%= request.servervariables("script_name") %>">
    Document Title

    <input type="text" name="u_title" size="35">



    Cell 1


    <textarea rows="2" name="u_cell1" cols="35"></textarea>



    Cell 2


    <textarea rows="2" name="u_cell2" cols="35"></textarea>
    <input type="submit" value="Submit" ></p>
    </form>
    </body>
    </html>
    <%
    else

    ' If there is a user inputted title
    ' get all of the user inputed values
    u_title=request.form("u_title")
    u_cell1=request.form("u_cell1")
    u_cell2=request.form("u_cell2")

    ' Varible created fo excel file name. Speces are changed to underscores
    ' and later the current date is added in attempts to create a unique file
    ' Users are not prevented from entering characters !@#$%^&*()+= that are
    ' invlaid file names in this example
    g_filename=replace(u_title," ","_")


    set fso = createobject("scripting.filesystemobject")
    ' create the text (xls) file to the server adding the -mmddyyyy after the g_title value
    Set act = fso.CreateTextFile(server.mappath(""&g_filename & "-"& month(date())& day(date())& year(date()) &".xls"), true)

    ' write all of the user input to the text (xls) document
    ' The .xls extension can just as easily be .asp or .inc whatever best suits your needs
    ' Providing that you remove the info contained in the header and remove the xml
    ' reference in the html tag that starts the page/excel file. It is to add gridlines and
    ' a title to the excel worksheet
    act.WriteLine "<html xmlns:x=""urn:schemas-microsoft-comffice:excel"">"
    act.WriteLine "<head>"
    act.WriteLine "<!--[if gte mso 9]><xml>"
    act.WriteLine "<x:ExcelWorkbook>"
    act.WriteLine "<x:ExcelWorksheets>"
    act.WriteLine "<x:ExcelWorksheet>"
    act.WriteLine "<x:Name>"& u_title &"</x:Name>"
    act.WriteLine "<x:WorksheetOptions>"
    act.WriteLine "<x:Print>"
    act.WriteLine "<x:ValidPrinterInfo/>"
    act.WriteLine "</x:Print>"
    act.WriteLine "</x:WorksheetOptions>"
    act.WriteLine "</x:ExcelWorksheet>"
    act.WriteLine "</x:ExcelWorksheets>"
    act.WriteLine "</x:ExcelWorkbook>"
    act.WriteLine "</xml>"
    act.WriteLine "<![endif]--> "
    act.WriteLine "</head>"
    act.WriteLine "<body>"
    act.WriteLine "<table>"
    act.WriteLine "<tr>"
    act.WriteLine "<td>"
    act.WriteLine u_cell1
    act.WriteLine "</td>"
    act.WriteLine "<TD>=Sum(c2:d2)*(1+E2)</TD>"
    act.WriteLine u_cell2
    act.WriteLine "</td>"
    act.WriteLine "</tr>"
    act.WriteLine "</table>"
    act.WriteLine "</body>"
    act.WriteLine "</html>"
    ' close the document
    act.close
    %>
    Your excel has been successfully create and can be viewed by clicking
    .xls" target="_blank">here
    <%
    end if
    %>
    </body>
    </html>

  6. #6
    devi riempire le celle personalizzando questa parte di codice


    act.WriteLine "<table>"
    act.WriteLine "<tr>"
    act.WriteLine "<td>"
    act.WriteLine u_cell1
    act.WriteLine "</td>"
    act.WriteLine "<TD>=Sum(c2:d2)*(1+E2)</TD>"
    act.WriteLine u_cell2
    act.WriteLine "</td>"
    act.WriteLine "</tr>"
    act.WriteLine "</table>"


    proprio come se costruissi una tabella HTML.

    Piuttosto, una curiosità: dici che le macchine (i client) che usano l'applicativo NON hanno Excel installato... cosa se ne fanno del foglio excel generato?

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    31
    si quello l' avevo capito ma come faccio a dirgli di scrivere all' interno del foglio "dati utente" nella cella A7 ?

    il motivo è perchè questo file viene inviato a un programma della casa madre che importandolo va a leggere i dati creati all' interno di un file excel...

    per non comprare licenze office sto cercando una soluzione... comunque su un server posso anche installarla una licenze ora che ci penso... una ce l' abbiamo... quindi i client non dovrebbero avere problemi giusto?

  8. #8
    con l'ultimo codice NON puoi andare direttamente a una cella specifica, diciamo che devi arrivarci sequenzialmente

    cerca di stabilire quale metodo vuoi usare (con o senza excel installato *sul server*), poi vediamo di risolvere gli eventuali problemi

  9. #9
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    31
    Ti chiedo, gentilmente, di darmi una mano senza l'utilizzo di una licenza office.

  10. #10
    ti ho già detto come fare

    Originariamente inviato da optime
    con l'ultimo codice NON puoi andare direttamente a una cella specifica, diciamo che devi arrivarci sequenzialmente

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.