У меня есть отчет для экспорта в Excel.Все работает нормально, но я не могу экспортировать изображение MyImage.jpg
?Как добавить iamge в столбец, чтобы отчет выглядел как https://www.screencast.com/t/xxVdQjLmL5G
.Моя единственная проблема в том, что я не могу экспортировать изображение.Как я могу это сделать?
Мой код в DataTable:
public IActionResult WorkOrderExportToExcel([FromBody] WorkOrderViewModel model)
{
var uploadPath = string.Format("uploads\\" + CurrentUserDetails.SellerID + "\\Excel\\");
var targetDirectory = Path.Combine(_iconfiguration["BManageFolder"], uploadPath);
if (!Directory.Exists(targetDirectory))
{
Directory.CreateDirectory(targetDirectory);
}
var filename = "workOrderReport" + DateTime.Now.ToShortDateString().Replace('/', '_') + ".xlsx";
var savePath = Path.Combine(targetDirectory, filename);
var loadURL = _iconfiguration["BManageUrl"] + uploadPath + filename;
DataTable MissingSingedDocumentList = ReportService.ExportWorkOrderExcel(model);
DataTable dtt = new DataTable();
dtt.Columns.Add("POSTING ORDER : INSTRUCTIONS & CONFIRMATION OF RECEIPT OF MATERIALS");
dtt.Columns.Add(" ");
dtt.Columns.Add(" ");
dtt.Columns.Add(" ");
dtt.Columns.Add(" ");
dtt.Columns.Add(" ");
dtt.Columns.Add(" ");
dtt.Columns.Add(" ");
dtt.Rows.Add("Date : " + DateTime.Now.ToShortDateString());
dtt.Rows.Add("From : " + model.Name);
dtt.Rows.Add("Email : " + model.Email);
dtt.Rows.Add("To : " + model.productionVendorOne + " " + model.productionVendorTwo);
dtt.Rows.Add("RE : " + model.JobName);
dtt.Rows.Add(" ");
dtt.Rows.Add("Market",/*,"Posting Date"*/model.OrderType + " Date","Unit #", "Media Owner", "Media Type", "Size", "Design", "Date Materials Received");
DataRow[] rows = MissingSingedDocumentList.Select();
foreach (DataRow dr in rows)
{
dtt.Rows.Add(dr.ItemArray);
}
dtt.Rows.Add("");
DataSet ds = new DataSet();
dtt.TableName = "Work Order Report";
ds.Tables.Add(dtt);
ExcelHelper.AppendMultipleSheetWhileDoingExportToExcel(ds, savePath);
return Ok(loadURL);
}
Моя функция AppendMultipleSheetWhileDoingExportToExcel имеет значение
using (var workbook = SpreadsheetDocument.Create(Savepath, SpreadsheetDocumentType.Workbook))
{
var workbookPart = workbook.AddWorkbookPart();
workbook.WorkbookPart.Workbook = new Workbook();
workbook.WorkbookPart.Workbook.Sheets = new Sheets();
//declare our MergeCells here
MergeCells mergeCells = null;
foreach (DataRow dsrow in table.Rows)
{
int innerColIndex = 0;
rowIndex++;
Row newRow = new Row();
foreach (String col in columns)
{
Stylesheet stylesheet1 = new Stylesheet();
Cell cell = new Cell();
cell.DataType = CellValues.String;
cell.CellValue = new CellValue(dsrow[col].ToString());
cell.CellReference = excelColumnNames[innerColIndex] + rowIndex.ToString();
if (table.TableName == "Work Order Report")
{
string cellNameWorkOrder = dsrow[col].ToString();
if (cellNameWorkOrder == "POSTER: 10% MUST HAVE APPROACH AND CLOSE-UP SHOTS - PHOTO OF EACH CREATIVE" || cellNameWorkOrder == "BULLETINS: 100% CLOSE-UP AND APPROACH OF EACH UNIT")
{
if (mergeCells == null)
mergeCells = new MergeCells();
var cellAddress = cell.CellReference;
var cellAddressTwo = "I" + rowIndex.ToString();
mergeCells.Append(new MergeCell() { Reference = new StringValue(cellAddress + ":" + cellAddressTwo) });
}
}
newRow.AppendChild(cell);
innerColIndex++;
}
sheetData.AppendChild(newRow);
}
//add the mergeCells to the worksheet if we have any
if (mergeCells != null)
sheetPart.Worksheet.InsertAfter(mergeCells, sheetPart.Worksheet.Elements<SheetData>().First());
}