프로젝트에서 사용자가 버튼을 클릭하면 interop 라이브러리가 일부 데이터를 가져와 엑셀 인스턴스에 씁니다.저장 대화 상자를 사용하여 생성 된 Excel 인스턴스를 클라이언트의 디스크에 저장하는 방법
이제 내가 원한다 : 엑셀 인스턴스가 모든 데이터를 가져올 때 대화 상자로 저장해야하며이 엑셀 인스턴스를 사용자 지정 경로에 저장해야합니다.
할 방법이 있습니까?
는편집 :
내 코드는 데이터를 엑셀 갈 수는 여기에 있습니다 :
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
서버에서 Excel을 사용하고 있습니까? ** **하지 마십시오. – SLaks
내 코드가 위입니다. 그것에 대해 무엇이 잘못 되었나요? – mavera
SLaks @ 1 +! 전 그렇게 생각하지 않아요! – sv88erik