C# 如何在API端转换excel?
问题是,如何在API中转换excel并作为文件传输回服务? 目前,我已经能够从数据库中获取数据,但从数据库中获取数据后,我不确定如何将数据转换为excel,然后再发送回服务。在从api获得完整的数据后,我需要在api中转换它,而不是在角度组件端C# 如何在API端转换excel?,c#,angular,visual-studio,angular6,C#,Angular,Visual Studio,Angular6,问题是,如何在API中转换excel并作为文件传输回服务? 目前,我已经能够从数据库中获取数据,但从数据库中获取数据后,我不确定如何将数据转换为excel,然后再发送回服务。在从api获得完整的数据后,我需要在api中转换它,而不是在角度组件端 [Route("getExcelData")] [Authenticate] [HttpPost] public IHttpActionResult GetExcelData([FromBody]Report obj)
[Route("getExcelData")]
[Authenticate]
[HttpPost]
public IHttpActionResult GetExcelData([FromBody]Report obj)
{
try
{
this.Contents.Add("Result", new ReportService().getExcelData(obj.Id, obj.FromDate, obj.ToDate));
return JsonResponse();
}
catch (Exception e)
{
LogManager.Instance.InsertLog(LogLevel.Error, e.Message, e.StackTrace, "ReportController", "ReportController", null, null);
ExceptionManager.Instance.Add(String.Format("GetData Failed: {0}", e.Message), $"{e.StackTrace} Inner Exception: {e.InnerException}");
this.Contents.Add("Result", null);
return JsonResponse();
}
}
下面的代码为我工作 请找到更多的私奔
我应该如何在代码中实现它?对不起,我真的不知道如何制作发行版。首先将数据作为表从DB提取到API中,然后根据XML进行转换。然后将其传递到
Path.GetFullPath
#region Loading the data to DataGridView
DataSet customersDataSet = new DataSet();
//Read the XML file with data
string inputXmlPath = Path.GetFullPath(@"../../Data/Employees.xml");
customersDataSet.ReadXml(inputXmlPath);
DataTable dataTable = new DataTable();
//Copy the structure and data of the table
dataTable = customersDataSet.Tables[1].Copy();
//Removing unwanted columns
dataTable.Columns.RemoveAt(0);
dataTable.Columns.RemoveAt(10);
this.dataGridView1.DataSource = dataTable;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.White;
dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightBlue;
dataGridView1.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)(System.Drawing.FontStyle.Bold)));
dataGridView1.ForeColor = Color.Black;
dataGridView1.BorderStyle = BorderStyle.None;
#endregion
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
//Create a workbook with single worksheet
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Import from DataGridView to worksheet
worksheet.ImportDataGridView(dataGridView1, 1, 1, isImportHeader: true, isImportStyle: true);
worksheet.UsedRange.AutofitColumns();
workbook.SaveAs("Output.xlsx");
}