Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I'm using this library from github: GitHub - barnhill/barcodelib: C# Barcode Image Generation Library[^]

I am getting the barcode image generated dynamically but now when I try to export to excel, no image is there and there is a cross sign (as if image not found).

I can understand its created dynamically and can't link to a path while writing to excel.

Can anyone help me out on this?

What I have tried:

I'm using the following code to export.

using (StringWriter sw = new StringWriter())
      {
          using (HtmlTextWriter hw = new HtmlTextWriter(sw))
          {
              //Create a Table.
              Table table = new Table();

              //Add Image control to the Table Cell.
              TableRow row = new TableRow();
              row.Cells.Add(new TableCell());
              row.Cells[0].Controls.Add(BarcodeImage);
              table.Rows.Add(row);

              //Render the Table as HTML.
              table.RenderControl(hw);

              //Export the Table to Excel.
              Response.Clear();
              Response.Buffer = true;
              Response.AddHeader("content-disposition", "attachment;filename=Images.xls");
              Response.Charset = "";
              Response.ContentType = "application/vnd.ms-excel";

              //Write the HTML string to Response.
              Response.Write(sw.ToString());
              Response.Flush();
              Response.End();
          }
      }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900