Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Jul 03, 2023 12:07 pm

Hi, I always got error when I want to view the excel file after get data from SQL. This is my code to get data from SQL

Code: Select all
        RtvCmd.CommandText = "SELECT Day1,Day2,Day3,Day4,Day5,Day6,Day7,Day8,Day9,Day10,Day11,Day12," &
                             " Day13,Day14,Day15,Day16,Day17,Day18,Day19,Day20,Day21,Day22,Day23,Day24," &
                             " Day25,Day26,Day27,Day28,Day29,Day30,TOTAL,MEAN,SIGMA FROM DLTPREPT WHERE" &
                             " DataField='No of INGOTS' AND Report='CW LEAD TIME REPORT ' AND QAAMON" &
                             " ='" & qaaMonLTCW & "' AND QAADAY ='" & qaaDayLTCW & "'"

        strconn.Open()
        RtvCmd.Connection = strconn
        RtvCmd.CommandTimeout = 100
        RtvCmd.ExecuteNonQuery()
        Rtvda.SelectCommand = RtvCmd
        Rtvda.Fill(Fillds)
        tblFill = Fillds.Tables(0)


Then, I want to plot to excel file that dedicated to this report.

Code: Select all
 If Dir(WebPath & "LeadtmRptCW.xlsx") <> "" Then
            Kill(WebPath & "LeadtmRptCW.xlsx")
        End If

        Dim wbLTCW As Workbook = New Workbook()
        wbLTCW.LoadFromFile(WebPath & "LeadtmRptCW.xls")
        Dim wsLTCW As Worksheet = wbLTCW.Worksheets(0)

        wsLTCW.Name = "Graph-LeadTime-CW"
        wsLTCW(1, 1).Value = "S.E.H.   SA  :  CW   CYCLETIME"
        wsLTCW(1, 27).Value = "Month of : " & fulldte

        For j = 0 To 29
            If Fillds.Tables(0).Rows(0).Item(j) = "-         " Then
                Fillds.Tables(0).Rows(0).Item(j) = "0"
            End If
            wsLTCW(35, j + 2).Value = Fillds.Tables(0).Rows(0).Item(j)
        Next

        wsLTCW(35, 35).Value = Fillds.Tables(0).Rows(0).Item(31)
        wsLTCW(36, 35).Value = Fillds.Tables(0).Rows(0).Item(32)
        wsLTCW.SaveToFile(WebPath2 & "LeadtmRptCW.xls", ExcelVersion.Version97to2003)

 Dim objFileInfoIGANRej As System.IO.FileInfo = New System.IO.FileInfo("D:\webtmp\LeadtmRptCW.xls") 'It should be change according to webpath
        Response.Clear()
        Response.ContentType = "application/vnd.ms-excel"
        Response.AppendHeader("Content-Disposition", "attachment; filename=LeadtmRptCW.xls")
        Response.TransmitFile(filename:=WebPath2 & "LeadtmRptCW.xls") 'It should be change according to webpath
        Response.End()
        Response.Flush()
        'Finally

        HttpContext.Current.Response.Flush() ' Sends all currently buffered output To the client.
        HttpContext.Current.Response.SuppressContent = True  ' Gets Or sets a value indicating whether To send HTTP content To the client.
        HttpContext.Current.ApplicationInstance.CompleteRequest() ' Causes ASP.NET To bypass all events And filtering In the HTTP pipeline chain Of execution And directly execute the EndRequest Event.


I can download the file however it does not show the way I wanted. I attach image file. A is the downloaded file. B is that I really want.


Previously I used Excel interop library and its working. Now want to implement spire. Is there anything that I left?
Attachments
B.png
B.png (45.04 KiB) Viewed 991 times
A.png
A.png (35.36 KiB) Viewed 991 times

emirafiq.ridzuan
 
Posts: 1
Joined: Wed Oct 17, 2018 12:12 am

Tue Jul 04, 2023 7:51 am

Hi,

Thank you for reaching out to us with your inquiry.
To better understand and address your specific issue, we kindly request that you provide us with the sql file and simplified code, this can help us provide you with a suitable solution in a timely manner. You can share them with us via email (support@e-iceblue.com) or attach them here. Thanks for your assistance in advance.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS