Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Mar 10, 2022 9:05 am

Hi Spire,

I have tried the free spire.xls on nuget on my MVC project... I somehow manage to write a piece of code that gets the uploaded file pass it on the stream and then load it... Below is my code

[Model]

public class OrderHeader{
[Key]
public int id { get; set; }
public DateTime document_date { get; set; }
[NotMapped]
public string document_date_view { get { return document_date.ToShortDateString(); } }
public string document_number { get; set; }
public int? platform_id { get; set; }
public string agency_id { get; set; }
public string advertiser_id { get; set; }
public int account_executive_id { get; set; }
}

[Controller]
OrderController

public async Task<IActionResult> Import(IFormFile file)
{
using (var stream = new MemoryStream())
{
await file.CopyToAsync(stream);
Workbook wbs = new Workbook();
wbs.LoadFromStream(stream);
Worksheet wks = wbs.Worksheets[0];
var agen = wks.Range["C4:C4"];
var adver = wks.Range["C4:C4"];
var prod = wks.Range["C6:C6"];
var camp = wks.Range["C7:C7"];
var cont = wks.Range["D4:D4"];
var desg = wks.Range["D5:D5"];
var refn = wks.Range["D7:D7"];
var docdt = wks.Range["G4:G4"];
var isbill = wks.Range["G6:G6"];

OrderHeader ord = new OrderHeader
{
ord.document_date = docdt.Value2
};
}

The red line is in ord.document_date = docdt.Value();

How can I pass the value of my CellRange variable to my Model property?

I want to pass this to the model so that I can do the saving using SaveChanges function of MVC

Thank you!

MonsurMon
 
Posts: 3
Joined: Thu Mar 10, 2022 7:07 am

Thu Mar 10, 2022 9:33 am

Hello,

Thank you for your inquiry.
Please modify the error code to the following code. If there is any question, just feel free to contact us.
Code: Select all
...
OrderHeader orderHeader = new OrderHeader();
orderHeader.document_date = (DateTime)docdt.Value2;
...

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS