Domanda

In un progetto quando l'utente fa clic su un pulsante, alcuni dati si ottiene e scritta a un'istanza Excel libreria di interoperabilità.

Ora, voglio che: Quando istanza di Excel ottenere tutti i dati, una finestra di dialogo Salva Muste essere aperto e salvare questo caso Excel per utente specificato percorso

.

C'è un modo per farlo?

Modifica:

Il mio codice per ottenere i dati in Excel è qui:

Public Sub ExportToExcel(ByVal dt As DataTable, ByVal outputPath As String)
    ' Create the Excel Application object
    Dim excelApp As New Microsoft.Office.Interop.Excel.ApplicationClass

    ' Create a new Excel Workbook
    Dim excelWorkbook As Excel.Workbook = excelApp.Workbooks.Add(Type.Missing)

    Dim excelSheet As Excel.Worksheet = excelWorkbook.Worksheets(1)
    excelApp.Visible = True
    ' Copy each DataTable as a new Sheet
    'sheetIndex += 1

    '' Create a new Sheet
    'excelSheet = CType( _
    '    excelWorkbook.Sheets.Add(excelWorkbook.Sheets(sheetIndex), _
    '    Type.Missing, 1, Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet), Microsoft.Office.Interop.Excel.Worksheet)

    excelSheet.Name = "Bayi"

    ' Copy the column names (cell-by-cell)
    For col = 0 To dt.Columns.Count - 1
        excelSheet.Cells(1, col + 1) = dt.Columns(col).ColumnName
    Next

    CType(excelSheet.Rows(1, Type.Missing), Microsoft.Office.Interop.Excel.Range).Font.Bold = True

    ' Copy the values (cell-by-cell)
    For col = 0 To dt.Columns.Count - 1
        For row = 0 To dt.Rows.Count - 1
            excelSheet.Cells(row + 2, col + 1) = dt.Rows(row).ItemArray(col)
        Next
    Next

    excelSheet = Nothing

    ' Save and Close the Workbook
    excelWorkbook.SaveAs(outputPath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, _
     Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, _
     Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)

    excelWorkbook.Close(True, Type.Missing, Type.Missing)

    excelWorkbook = Nothing

    ' Release the Application object
    excelApp.Quit()
    excelApp = Nothing

    ' Collect the unreferenced objects
    GC.Collect()
    GC.WaitForPendingFinalizers()

End Sub
È stato utile?

Soluzione

Non sono sicuro, che questo è ciò che si vuole, ma se si vuole consentire a un utente scarica un file excel, che avete creato sul lato server, quindi basta scrivere il contenuto del file excel alla risposta , impostare il tipo MIME corretto - e ci si va! Post scriptum Non dimenticare di cancellare la risposta attualmente generato.

Altri suggerimenti

Se la prova di u per aggiungerlo al cliente da un server web, non c'è modo questo caso. Senza ottenere è di installare un Flash / Silverlight su client o qualcosa di simile, di andare oltre la sicurezza del software client browser.

Aggiornamento: Il suo è " Un rapido sguardo a Silverlight 3: Salva file di dialogo " E come leggere e scrivere i file in JavaScript

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top