.net core mvc 怎么做类似病例表格编辑器,记录每天病人体征参数,可以编辑,新增,打印,导出,能读取表格内容变化,如能帮做出费用可增加,最好有案列


.net core mvc 怎么做类似病例表格编辑器,记录每天病人体征参数,可以编辑,新增,打印,导出,能读取表格内容变化,如能帮做出费用可增加,最好有案列


关注
using System;
using System.Collections.Generic;
using System.IO;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
namespace YourNamespace{public class ExcelGenerator{public static void GenerateExcel(List<
Patient>
patients){string filePath = "
PatientsData.xlsx"
;
using (SpreadsheetDocument document = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook)){WorkbookPart workbookPart = document.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookPart.AddNewPart<
WorksheetPart>
();
SheetData sheetData = new SheetData();
worksheetPart.Worksheet = new Worksheet(sheetData);
Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "
PatientsData"
};
sheets.Append(sheet);
Row headerRow = new Row();
headerRow.Append(CreateCell("
Patient ID"
));
headerRow.Append(CreateCell("
Name"
));
headerRow.Append(CreateCell("
Temperature"
));
headerRow.Append(CreateCell("
Blood Pressure"
));
sheetData.AppendChild(headerRow);
foreach (var patient in patients){Row dataRow = new Row();
dataRow.Append(CreateCell(patient.PatientId));
dataRow.Append(CreateCell(patient.Name));
dataRow.Append(CreateCell(patient.Temperature));
dataRow.Append(CreateCell(patient.BloodPressure));
sheetData.AppendChild(dataRow);
}
workbookPart.Workbook.Save();
}}
private static Cell CreateCell(string text){Cell cell = new Cell();
cell.DataType = CellValues.String;
cell.CellValue = new CellValue(text);
return cell;
}}
public class Patient{public int PatientId { get;
set;
}public string Name { get;
set;
}public decimal Temperature { get;
set;
}public string BloodPressure { get;
set;
}}}这段代码演示了如何使用DocumentFormat.OpenXml库生成一个Excel文件,其中记录了每天不同病人的体征参数(例子中包括PatientId、Name、Temperature和BloodPressure)。可以根据实际情况修改字段和内容。