Excel保存在C:\\ My Documents Default中

时间:2009-09-02 12:43:46

标签: vb.net excel

我正在将数据导出到excel并尝试保存到我的应用程序中的文件夹...但是excel默认保存在C:\ Documents中但我想保存在E:\ Apllication \ Reports

以下是我生成Excel工作表的代码

    If ComDset.Tables(0).Rows.Count > 0 Then

        Try
            With Excel
                .SheetsInNewWorkbook = 1
                .Workbooks.Add()
                .Worksheets(1).Select()

                Dim i As Integer = 1
                For col = 0 To ComDset.Tables(0).Columns.Count - 1
                    .cells(1, i).value = ComDset.Tables(0).Columns(col).ColumnName
                    .cells(1, i).EntireRow.Font.Bold = True
                    i += 1
                Next
                i = 2
                Dim k As Integer = 1
                For col = 0 To ComDset.Tables(0).Columns.Count - 1
                    i = 2
                    For row = 0 To ComDset.Tables(0).Rows.Count - 1
                        .Cells(i, k).Value = ComDset.Tables(0).Rows(row).ItemArray(col)
                        i += 1
                    Next
                    k += 1
                Next
                filename = "ShiftReport" & Format(MdbDate, "dd-MM-yyyy") & ".xls"
                .ActiveCell.Worksheet.SaveAs(filename)
            End With
            System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
            Excel = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        ' The excel is created and opened for insert value. We most close this excel using this system
        Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
        For Each i As Process In pro
            i.Kill()
        Next
    End If

告诉我如何为标题指定颜色

提前致谢

1 个答案:

答案 0 :(得分:3)

你试过这个吗?

.ActiveCell.Worksheet.SaveAs("E:\Apllication\Reports\" & filename)