Hi,
public FileContentResult CreateExcel(string org, string loc, out string errormessage)
{
FileContentResult retXLS = null;
XlsFile Xls;
try
{
errormessage = string.Empty;
List<MarkItemModel> itemlist = (List<MarkItemModel>)GetMarkItems(org, loc, string.Empty, out errormessage);
if (itemlist != null)
{
Xls = new XlsFile(true);
Xls.NewFile(1);
//Global Workbook Options
Xls.OptionsAutoCompressPictures = false;
//Styles.
TFlxFormat StyleFmt;
StyleFmt = Xls.GetStyle(Xls.GetBuiltInStyleName(TBuiltInStyle.Normal, 0));
StyleFmt.Font.Name = "Arial";
StyleFmt.Font.Size20 = 200;
StyleFmt.Font.Color = TExcelColor.Automatic;
StyleFmt.Font.Family = 0;
StyleFmt.Font.Scheme = TFontScheme.None;
Xls.SetStyle(Xls.GetBuiltInStyleName(TBuiltInStyle.Normal, 0), StyleFmt);
//Set up rows and columns
//Xls.DefaultColWidth = 2925;
Xls.DefaultColWidth = 5000;
Xls.DefaultRowHeight = 1200;
Xls.DefaultRowHeightAutomatic = false;
int idx = 1;
Xls.SetCellValue(idx, 1, "UIC");
Xls.SetCellValue(idx, 2, "System Item Mark");
Xls.SetCellValue(idx, 3, "NSN");
Xls.SetCellValue(idx, 4, "Part Number");
Xls.SetCellValue(idx, 5, "Nomenclature");
Xls.SetCellValue(idx, 6, "Serial Number");
Xls.SetCellValue(idx, 7, "Has Part Image");
Xls.SetCellValue(idx, 8, "UCN");
Xls.SetCellValue(idx, 9, "UID Mark");
Xls.SetCellValue(idx, 10, "Not Installed Reason");
foreach (MarkItemModel itm in itemlist)
{
idx += 1;
Xls.SetAutoRowHeight(idx, false);
Xls.SetRowHeight(idx, 1200);
Xls.SetColWidth(1, 3200);
Xls.SetCellValue(idx, 1, itm.UIC.LocationName);
Xls.SetColWidth(2, 2925);
Bitmap em = EncodeMark(itm.ItemIdentifier + Convert.ToChar(4));
using (MemoryStream ms = new MemoryStream())
{
em.Save(ms, ImageFormat.Jpeg);
TImageProperties ImgProps = new TImageProperties();
ImgProps.Anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, idx, 32, 2, 32, idx + 1, 0, 3, 0);
ImgProps.ShapeName = itm.ItemIdentifier;
Xls.AddImage(ms.ToArray(), ImgProps);
}
Xls.SetColWidth(3, 4000);
Xls.SetCellValue(idx, 3, itm.NSN);
Xls.SetColWidth(4, 6000);
Xls.SetCellValue(idx, 4, itm.OriginalPartNumber);
Xls.SetColWidth(5, 4000);
TFlxFormat fmt = Xls.GetFormat(Xls.GetColFormat(5));
fmt.WrapText = true;
Xls.SetColFormat(5, Xls.AddFormat(fmt));
Xls.SetCellValue(idx, 5, itm.Description);
Xls.SetColWidth(6, 6000);
Xls.SetCellValue(idx, 6, itm.SerialNumber);
Xls.SetColWidth(7, 6000);
Xls.SetCellValue(idx, 7, itm.HasPartCatalogPicture.ToString());
Xls.SetColWidth(8, 6000);
Xls.SetCellValue(idx, 8, itm.UCN);
Xls.SetColWidth(9, 2925);
if (string.IsNullOrEmpty(itm.UII))
{
Xls.SetCellValue(idx, 9, itm.UII);
}
else
{
Xls.SetCellValue(idx, 9, " ");
}
Xls.SetCellValue(idx, 10, itm.TagInstallationStatus);
}
byte[] filebytes;
using (MemoryStream xlsfilestream = new MemoryStream())
{
Xls.Save(xlsfilestream, TFileFormats.Xlsx);
filebytes = xlsfilestream.ToArray();
}
retXLS = new FileContentResult(filebytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}
catch (Exception ex)
{
errormessage = "Error attempting to create Excel file: " + ex.ToString();
return retXLS;
}
finally
{
Xls = null;
}
return retXLS;
}