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 Jun 03, 2021 1:57 pm

Hello,
i use Spire.XLS version 11.6.0 on my .net project.
It works in local but when i deploy on docker, i have this exeption: "The type initializer for 'Spire.Xls.Core.Spreadsheet.XlsPageSetupBase' threw an exception."

could you help me or give me some leads?
maybe about dlls or linux container or libgdiplus.

franck.martin
 
Posts: 2
Joined: Wed Dec 16, 2020 10:13 am

Fri Jun 04, 2021 1:49 am

Hello,

Thanks for your inquiry.
Do you add the following command to your dockerfile? If not, please try again after adding this command.
Code: Select all
# install System.Drawing native dependencies
RUN apt-get update \

    && apt-get install -y --allow-unauthenticated \

        libc6-dev \

        libgdiplus \

        libx11-dev \

     && rm -rf /var/lib/apt/lists/*

If the issue still occurs, to help us reproduce your issue and help you solve it, please provide your input file, your complete code (or a runnable project) along with your dockerfile to help us investigate further. You could send them to us (support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Jun 04, 2021 8:36 am

Thanks a lot, it works great :)

franck.martin
 
Posts: 2
Joined: Wed Dec 16, 2020 10:13 am

Fri Jun 04, 2021 8:43 am

You are welcome.
If you encounter any issues related to our products in the future, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Apr 13, 2022 11:52 am

The type initializer for 'Spire.Xls.Core.Spreadsheet.XlsPageSetupBase' throw exception error I am getting. It is working fine locally but when deployed in server it started throwing error.

My complete code is below. Kindly help.

MemoryStream sw = new MemoryStream();
using (Stream responseStream = _s3BucketServices.GetStreamFromS3File(sourceBucketName, file).Result)
using (MemoryStream memStream = new MemoryStream())
{
responseStream.CopyTo(memStream);
memStream.Seek(0, SeekOrigin.Begin);
//using (FileStream fs = File.OpenRead(@"D:\Users\agupta1\Downloads\Input\" + file))
using (Workbook workBook = new Workbook())
{
workBook.LoadFromStream(memStream);
//workBook.LoadFromStream(fs);
var cn = 0;
foreach (var dt in dts)
{
//String line;
Boolean header = false;
Boolean continueReading = false;
var fieldPositions = new List<int>();
int totalFields = -1;
var currentRow = 1;
var workSheet = workBook.Worksheets[cn];
foreach (DataRow row in dt.Rows)
{
try
{
//line = string.Join(",", row.ItemArray.Select(x => x.ToString().Trim()));
String[] fileLine = row.ItemArray.Select(x => x.ToString().Trim()).ToArray();

if (fileLine.Where(x => !String.IsNullOrEmpty(x)).Count() == 1
|| fileLine.All(x => String.IsNullOrEmpty(x)))
{
fieldPositions = new List<int>();
header = false;
continueReading = false;
totalFields = -1;
}
else
{
if (continueReading == false) header = true;

if (header && continueReading == false)//establish the position
{
int pos = 0;
foreach (string st in fileLine)
{
foreach (var item in ignoreColumns)
{
if (st.ToUpper() == item)
{
fieldPositions.Add(pos);
}
}
pos++;
}
totalFields = pos;
continueReading = true;
}
else
{
if (fileLine.Where(x => !String.IsNullOrEmpty(x)).Count() > 1)
{
if (fieldPositions.Count >= 0)
{
foreach (var item in fieldPositions)
{
workSheet.SetCellValue(currentRow, item + 1, "####");
}

}
}
}
}

//line = string.Empty;
currentRow++;
}
catch (Exception ex)
{
throw ex;
}
}
cn++;
}

workBook.SaveToStream(sw);
//using (var fileStream = File.Create("D:\\ShareFile\\" + file))
//{
// sw.Seek(0, SeekOrigin.Begin);
// sw.CopyTo(fileStream);
//}
_s3BucketServices.Upload(sw, destinationBucketName, file);
}
}
Attachments
fraw3t0504.zip
Attaching file for your reference.
(11.92 KiB) Downloaded 104 times

apurwagupta08
 
Posts: 1
Joined: Wed Apr 13, 2022 11:49 am

Thu Apr 14, 2022 3:07 am

Hi, I have the same problem. It works fine locally, but when I deploy on docker, I have this exeption: 'Spire.Xls.Core.Spreadsheet.XlsPageSetupBase' threw an exception. at Spire.Xls.Core.Spreadsheet.XlsWorksheet.InitializeCollections().
These lines were already added in my dockerfile.
apt-get update && apt-get install -y --allow-unauthenticated libc6-dev libgdiplus libx11-dev && rm -rf /var/lib/apt/lists/*
but I continue with the same error.
Thanks in advance.

raudelchavez
 
Posts: 1
Joined: Wed Apr 13, 2022 5:24 pm

Thu Apr 14, 2022 10:30 am

Hi apurwagupta08,

Thank you for your inquiry.
To help us investigate your issue accurately and quickly, please provide the following information. Thanks in advance.
1) The server information, such as winserver2012
2) The type of application, such as Console App (.NET Framework 4.6)

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Thu Apr 14, 2022 10:32 am

raudelchavez wrote:Hi, I have the same problem. It works fine locally, but when I deploy on docker, I have this exeption: 'Spire.Xls.Core.Spreadsheet.XlsPageSetupBase' threw an exception. at Spire.Xls.Core.Spreadsheet.XlsWorksheet.InitializeCollections().
These lines were already added in my dockerfile.
apt-get update && apt-get install -y --allow-unauthenticated libc6-dev libgdiplus libx11-dev && rm -rf /var/lib/apt/lists/*
but I continue with the same error.
Thanks in advance.


Hi,

Thank you for your inquiry.
To help us investigate your issue accurately and quickly, please provide the following information. You can attach your file here or send it to us via email (support@e-iceblue.com). Thanks in advance.
1) Your Excel test document and test code
2) The type of application, such as Console App(.NET Core 2.1)
3) Your Dockerfile

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Thu Apr 14, 2022 10:36 am

apurwagupta08 wrote:The type initializer for 'Spire.Xls.Core.Spreadsheet.XlsPageSetupBase' throw exception error I am getting. It is working fine locally but when deployed in server it started throwing error.

My complete code is below. Kindly help.

MemoryStream sw = new MemoryStream();
using (Stream responseStream = _s3BucketServices.GetStreamFromS3File(sourceBucketName, file).Result)
using (MemoryStream memStream = new MemoryStream())
{
responseStream.CopyTo(memStream);
memStream.Seek(0, SeekOrigin.Begin);
//using (FileStream fs = File.OpenRead(@"D:\Users\agupta1\Downloads\Input\" + file))
using (Workbook workBook = new Workbook())
{
workBook.LoadFromStream(memStream);
//workBook.LoadFromStream(fs);
var cn = 0;
foreach (var dt in dts)
{
//String line;
Boolean header = false;
Boolean continueReading = false;
var fieldPositions = new List<int>();
int totalFields = -1;
var currentRow = 1;
var workSheet = workBook.Worksheets[cn];
foreach (DataRow row in dt.Rows)
{
try
{
//line = string.Join(",", row.ItemArray.Select(x => x.ToString().Trim()));
String[] fileLine = row.ItemArray.Select(x => x.ToString().Trim()).ToArray();

if (fileLine.Where(x => !String.IsNullOrEmpty(x)).Count() == 1
|| fileLine.All(x => String.IsNullOrEmpty(x)))
{
fieldPositions = new List<int>();
header = false;
continueReading = false;
totalFields = -1;
}
else
{
if (continueReading == false) header = true;

if (header && continueReading == false)//establish the position
{
int pos = 0;
foreach (string st in fileLine)
{
foreach (var item in ignoreColumns)
{
if (st.ToUpper() == item)
{
fieldPositions.Add(pos);
}
}
pos++;
}
totalFields = pos;
continueReading = true;
}
else
{
if (fileLine.Where(x => !String.IsNullOrEmpty(x)).Count() > 1)
{
if (fieldPositions.Count >= 0)
{
foreach (var item in fieldPositions)
{
workSheet.SetCellValue(currentRow, item + 1, "####");
}

}
}
}
}

//line = string.Empty;
currentRow++;
}
catch (Exception ex)
{
throw ex;
}
}
cn++;
}

workBook.SaveToStream(sw);
//using (var fileStream = File.Create("D:\\ShareFile\\" + file))
//{
// sw.Seek(0, SeekOrigin.Begin);
// sw.CopyTo(fileStream);
//}
_s3BucketServices.Upload(sw, destinationBucketName, file);
}
}


Hi,

Thank you for your inquiry.
To help us investigate your issue accurately and quickly, please provide the following information. Thanks in advance.
1) The server information, such as winserver2012
2) The type of application, such as Console App (.NET Framework 4.6)

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Sun Oct 02, 2022 11:32 am

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

brianenno
 
Posts: 3
Joined: Sun Oct 02, 2022 11:20 am

Mon Oct 03, 2022 10:45 am

brianenno wrote: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


Hello,

Thank you for your inquiry.
Please note that System.Drawing.Common is no longer supported on non-Windows operating systems in the.net6 framework. Please check the official Microsoft note:
https://docs.microsoft.com/en-us/dotnet ... ndows-only

If you install Spire.Xls directly from the Nuget manager, the Net6 dll of Spire.Xls and System.Drawing.Common will be automatically install, that’s what’s causing your issue. To solve this issue, please use Spire.Xlsfor.NET Standard and install SkiaSharp.NativeAssets.Linux.NoDependencies. You can directly install Spire.Officefor.NETStandard from to use the function of Spire.Xls, or you can download the Spire.Xls from the following link then reference the dll of “netstandard2.0” folder to your project after unzip.
https://www.e-iceblue.com/Download/down ... t-now.html

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Tue Oct 04, 2022 4:18 pm

Thank you it worked!
The only problem is that I see an "Evaluation Warning" on the first page where it says "Buy Now!".
Is there a free Spire.XLS net.standard available to use?
Thanks and regards

brianenno
 
Posts: 3
Joined: Sun Oct 02, 2022 11:20 am

Wed Oct 05, 2022 1:26 am

Hello,

Please download Free Spire.Xls for .NET via the below links.
Our website link:https://www.e-iceblue.com/Download/download-excel-for-net-free.html
NuGet link: https://www.nuget.org/packages/FreeSpire.XLS/

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Oct 05, 2022 3:25 pm

Hello,
the problem of the "download-excel-for-net-free" solution is that .Net 6.0 and the component "System.Drawing.Common" are used, which will let it to crash when is executed under a linux environment (docker).
Is there a way to use the free version in ".net standard 2.0" mode?

Thanks and regards,
Brianenno

brianenno
 
Posts: 3
Joined: Sun Oct 02, 2022 11:20 am

Thu Oct 06, 2022 3:21 am

Hello,

Thanks for your feedback.
According to your description, manually import all the DLLS in the folder named "netstandard2.0" (as shown in the screenshot) and then install the following three external references through the NuGet manager.
SkiaSharp >= 1.68.0
System.Text.Encoding.CodePages >= 4.5.0
System.Security.Cryptography.Xml >=4.5.0

Sincerely,
Annika
E-iceblue support team
Attachments
screenshot.png
screenshot.png (18.63 KiB) Viewed 2522 times
User avatar

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

Return to Spire.XLS