Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9001333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:25:21+00:00 2026-06-16T00:25:21+00:00

I’m trying to save my chart image so that I can put it into

  • 0

I’m trying to save my chart image so that I can put it into an excel file created using epplus

Response.ContentType = "image/bmp"
    Response.AppendHeader("Content-Disposition", "attachment;filename=chart.bmp")
    Chart1.SaveImage(Response.OutputStream)

    Dim imgchart As Bitmap
    imgchart = New Bitmap("chart.bmp")

Using package As New ExcelPackage(newFile)
        ' add a new worksheet to the empty workbook
        Dim worksheet As ExcelWorksheet = package.Workbook.Worksheets.Add("LIMS")
        'Add the headers
        worksheet.Cells(1, 1).Value = "Analyzer Time"
        worksheet.Cells(1, 2).Value = "Analyzer Data"
        worksheet.Cells(1, 3).Value = "Lab Date"
        worksheet.Cells(1, 4).Value = "Lab Data"
        Dim row
        row = 2
        For i = 0 To count1 - 1
            worksheet.Cells(row, 1).Value = col1(i)
            worksheet.Cells(row, 2).Value = col2(i)
            row = row + 1
        Next
        row = 2
        For i = 0 To labcount - 1
            worksheet.Cells(row, 3).Value = col3(i)
            worksheet.Cells(row, 4).Value = col4(i)
            row = row + 1
        Next

        worksheet.Drawings.AddPicture("chart", imgchart)
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
        package.SaveAs(Response.OutputStream)

        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
        Response.WriteFile("chart.xlsx")
        Response.End()
    End Using

What do I need to fix in this code? I’m new to file streams and response.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:25:21+00:00Added an answer on June 16, 2026 at 12:25 am

    From a quick glance, I think you are making a couple mistakes. First it seems you are trying to send the image and the excel through the response. I don’t believe you can send multiple files to the client, but you don’t need to send the image anyways since you are just inserting it into the excel file. Also with the image you are attempting to load the bitmap from the non-existent server file “chart.bmp”. Second, you are using the function Response.WriteFile which writes a disk file to the response. I’m guessing that’s not what you are trying to do since you have already written the file to the response with Package.SaveAs. Try this code below,

        'Save the chart to a memory stream instead of a file 
        Dim BitMapMS As New MemoryStream
        Chart1.SaveImage(BitMapMS)
        'Load bitmap from memory stream
        Dim imgchart As Bitmap
        imgchart = New Bitmap(BitMapMS)
    
    Using package As New ExcelPackage(newFile)
            ' add a new worksheet to the empty workbook
            Dim worksheet As ExcelWorksheet = package.Workbook.Worksheets.Add("LIMS")
            'Add the headers
            worksheet.Cells(1, 1).Value = "Analyzer Time"
            worksheet.Cells(1, 2).Value = "Analyzer Data"
            worksheet.Cells(1, 3).Value = "Lab Date"
            worksheet.Cells(1, 4).Value = "Lab Data"
            Dim row
            row = 2
            For i = 0 To count1 - 1
                worksheet.Cells(row, 1).Value = col1(i)
                worksheet.Cells(row, 2).Value = col2(i)
                row = row + 1
            Next
            row = 2
            For i = 0 To labcount - 1
                worksheet.Cells(row, 3).Value = col3(i)
                worksheet.Cells(row, 4).Value = col4(i)
                row = row + 1
            Next
    
            worksheet.Drawings.AddPicture("chart", imgchart)
    
            'Clear the response
            Response.Clear()
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"            
            Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
            'This call looks like it will write the data to the stream.
            package.SaveAs(Response.OutputStream)
    
    
            Response.End()
        End Using
    

    I can’t test the above code, so give it a try and let us know how it goes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.