I want to export excel sheet with qr-code images in my table. The qrcode saved with its serial number and i generate it with google apis. I do it in controller that return MvcHtmlString
and i use it in my view like @Html.QRCode(item.SerialNumber, 80, 0)
and it works in my view well.
my Controller
public static MvcHtmlString QRCode(this HtmlHelper htmlHelper, string data, int size = 80, int margin = 4, QRCodeErrorCorrectionLevel errorCorrectionLevel = QRCodeErrorCorrectionLevel.Low, object htmlAttributes = null)
{
if (data == null)
throw new ArgumentNullException("data");
if (size < 1)
throw new ArgumentOutOfRangeException("size", size, "Must be greater than zero.");
if (margin < 0)
throw new ArgumentOutOfRangeException("margin", margin, "Must be greater than or equal to zero.");
if (!Enum.IsDefined(typeof(QRCodeErrorCorrectionLevel), errorCorrectionLevel))
throw new InvalidEnumArgumentException("errorCorrectionLevel", (int)errorCorrectionLevel, typeof(QRCodeErrorCorrectionLevel));
var url = string.Format("http://chart.apis.google.com/chart?cht=qr&chld={2}|{3}&chs={0}x{0}&chl={1}", size, HttpUtility.UrlEncode(data), errorCorrectionLevel.ToString()[0], margin);
var tag = new TagBuilder("img");
if (htmlAttributes != null)
tag.MergeAttributes(new RouteValueDictionary(htmlAttributes));
tag.Attributes.Add("src", url);
tag.Attributes.Add("width", size.ToString());
tag.Attributes.Add("height", size.ToString());
return new MvcHtmlString(tag.ToString(TagRenderMode.SelfClosing));
}
To export excel sheet i do the following :
- create a grid
- give it the Data Source of the desired data .
the qrcode data that i give to the grid view is
data.QRcode = atm.SerialNumber;
it actually get the string of qrcode how to get its qrcode image of its code like in my view that i use
@Html.QRCode(item.SerialNumber, 80, 0)
Note : i need any solution that can get the qrcode image and other data external to print it.
Update : I reached to the source of the image then if any solution for how to display image in excel sheet according to the source of the image . detailed steps : 1- get the link of the image like with google apis
System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
image.ImageUrl = url;
image.Width = 80;
image.Height = 80;
atm2.QRcode = image;
but this column doesn't appear in the exported excel sheet
Thanks for any help .