Background:
- Given a spreadsheet template, to generate a new spreadsheet by filling the information and barcode.
- E.g. the screenshot (template) below, the barcode to be inserted at the cell location.
What I have done:
- I manage to locate the target cell index (by searching the keyword $PART_NAME_LABEL$).
Question:
- How to insert the barcode (image) at the target cell index location?
- Any other suggestions for barcode generation? (Instead of inserting the barcode image, e.g. using barcode font)
I have referred to the sample in this page but it doesn't work.
XlsxFormatProvider formatProvider = new XlsxFormatProvider();
Workbook workbook = formatProvider.Import(File.ReadAllBytes(@"C:\temp\temp.xlsx"));
var worksheet = workbook.Sheets[0] as Worksheet;
FindOptions f = new FindOptions();
f.FindWhat = "$PART_NAME_LABEL$";
IEnumerable<FindResult> result = worksheet.FindAll(f);
foreach(var i in result)
{
worksheet.Cells[i.FoundCell.CellIndex].SetValue("");
//Add barcode here
RadBarcode radBarcode1 = new RadBarcode();
Telerik.WinControls.UI.Barcode.Symbology.Code39Extended code39Extended1 = new Telerik.WinControls.UI.Barcode.Symbology.Code39Extended();
radBarcode1.Symbology = code39Extended1;
radBarcode1.Value = "123456";
radBarcode1.LoadElementTree();
var ms = new MemoryStream();
Image barcode = radBarcode1.ExportToImage();
barcode.Save(ms, ImageFormat.Png);
FloatingImage image = new FloatingImage(worksheet, i.FoundCell.CellIndex, 35, 10);
image.ImageSource = new Telerik.Windows.Documents.Media.ImageSource(ms, "png");
}