Dear E-Iceblue support team,
I'm experiencing the same issues. My code run perfectly on my development/local machine (which is a windows10), but when is deployed on a kubernetes pod I get the error:
The type initializer for 'Spire.Xls.Core.Spreadsheet.XlsPageSetupBase' threw an exception.
.
1) the "Spire.Xls.Core" version is 12.07
2) I'm using microsoft net6.0
3) this is my C# code:
- Code: Select all
public string GenerateExcel(List<NumberOfPatientsForDoctorDTO> numberOfPatientsForDoctorDTOs, string sheetName)
{
string excelFileName = Guid.NewGuid().ToString() + ".xlsx";
string filePath = Path.Combine(Environment.CurrentDirectory, _smtpClientOptionMonitor.ExcelOutputFolder, excelFileName);
_logger.LogDebug($"The file path is '{filePath}'.");
try
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add(ExcelConstants.DOCTOR_NAME_COLUMN_NAME);
dataTable.Columns.Add(ExcelConstants.NUMBER_OF_PATIENTS_COLUMN_NAME);
foreach (var numberOfPatientsForDoctorRow in numberOfPatientsForDoctorDTOs)
{
DataRow row = dataTable.NewRow();
row[ExcelConstants.DOCTOR_NAME_COLUMN_NAME] = numberOfPatientsForDoctorRow.DoctorName;
row[ExcelConstants.NUMBER_OF_PATIENTS_COLUMN_NAME] = numberOfPatientsForDoctorRow.NumberOfPatients;
dataTable.Rows.Add(row);
}
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = sheetName;
workbook.Worksheets["Sheet2"].Remove();
workbook.Worksheets["Sheet3"].Remove();
sheet.InsertDataTable(dataTable, true, 1, 1);
sheet.AllocatedRange.AutoFitRows();
sheet.AllocatedRange.AutoFitColumns();
workbook.SaveToFile(filePath, ExcelVersion.Version2016);
_logger.LogDebug($"The excel file '{excelFileName}' has been created into '{filePath}' folder.");
}
catch (Exception ex)
{
_logger.LogError($"A tragic exception has been occurred. The message is '{ex.Message}'.");
if(ex.InnerException != null)
{
_logger.LogError($"The inner exception is '{ex.InnerException.Message}'.");
}
}
return excelFileName;
}
4) this is my dockerfile:
- Code: Select all
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
EXPOSE 5000
ARG FOLDER
ENV ASPNETCORE_URLS="http://0.0.0.0:5000"
ENV ASPNETCORE_ENVIRONMENT=Development
WORKDIR /app
COPY ./${FOLDER} .
ARG PROJECT
RUN echo "#!/bin/bash \n dotnet ${PROJECT}.dll" > ./dotnetProcessStart.sh
RUN chmod +x ./dotnetProcessStart.sh
RUN apt-get update && apt-get install -y --allow-unauthenticated libc6-dev libgdiplus libx11-dev && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["./dotnetProcessStart.sh"]
Where I'm doing it wrong? Can you help me fix this issues?
Thank you for your attention and effort,
Ennio