We have been using the Gembox trial version in the docker container(with Linux host) but the worksheet’s columns are getting squeezed.
Below is the docker file content:
WORKDIR "/src/Benchmarking360.API"
RUN dotnet build "Benchmarking360.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Benchmarking360.API.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
# Update package sources to include supplemental packages (contrib archive area).
RUN sed -i 's/main/main contrib/g' /etc/apt/sources.list
# Downloads the package lists from the repositories.
RUN apt-get update
# Install font configuration.
RUN apt-get install -y fontconfig
# Install Microsoft TrueType core fonts.
RUN apt-get install -y ttf-mscorefonts-installer
# Or install Liberation TrueType fonts.
#RUN apt-get install -y fonts-liberation
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Benchmarking360.API.dll"]
Adding code for the reference:
public static ExcelFile GenerateFile(List<Sec10K> sec10Ks)
{
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
// Continue to use the component in a Trial mode when free limit is reached.
SpreadsheetInfo.FreeLimitReached += (sender, e) => e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;
List<string> consolidatedTagValues = new List<string>();
// initiate an instance of Workbook
var book = new ExcelFile();
var worksheet = book.Worksheets.Add("Summary of Sig Acc Polici");
worksheet.Rows[0].Style = book.Styles[BuiltInCellStyleName.Heading4];
worksheet.Rows[0].Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(211, 211, 211), SpreadsheetColor.FromArgb(211, 211, 211));
worksheet.SetDefaultColumnWidth(150, LengthUnit.Pixel);
//worksheet.Columns[0].SetWidth(500, LengthUnit.Pixel);
worksheet.Cells[0, 0].Value = "Company";
worksheet.Cells[0, 0].Style.Font.Color = SpreadsheetColor.FromName(ColorName.Black);
worksheet.Columns[0].Style.WrapText = true;
worksheet.Columns[0].Style.VerticalAlignment = VerticalAlignmentStyle.Center;
worksheet.Columns[0].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
var cells = worksheet.Cells;
int index = 1;
foreach (var company in sec10Ks)
{
cells[index, 0].Value = company.CompanyName;
cells[index, 0].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
index++;
foreach (var tag in company.SignificantAccountingPolicies.Select(x => x.SourceTagName))
{
if (!consolidatedTagValues.Contains(tag))
{
consolidatedTagValues.Add(tag);
}
}
}
//columnpolicies
int header = 1;
for (int i = 0; i < consolidatedTagValues.Count; i++)
{
cells[0, header].Style.WrapText = true;
cells[0, header].Value = consolidatedTagValues[i];
header++;
}
int rowCount = 1;
int columnCount = 1;
for (int i = 0; i < consolidatedTagValues.Count; i++)
{
rowCount = 1;
foreach (var c in sec10Ks)
{
if (c.SignificantAccountingPolicies.Any(item => item.SourceTagName == consolidatedTagValues[i]))
{
HtmlLoadOptions h = new HtmlLoadOptions();
var htmk = "<span style='font-size:10pt;text-align:center'>✓</span>";
cells[rowCount, columnCount].SetValue(htmk, h);
}
else
{
HtmlLoadOptions h = new HtmlLoadOptions();
var htmk = "<span style='font-size:10pt;text-align:center'>✗</span>";
cells[rowCount, columnCount].SetValue(htmk, h);
}
cells[rowCount, columnCount].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
rowCount++;
}
columnCount++;
}
var hyperlinkStyle = book.Styles[BuiltInCellStyleName.Hyperlink];
//creating sheets & adding hyperlinks to tag
int headerTag = 1;
for (int i = 0; i < consolidatedTagValues.Count; i++)
{
string sheetname = consolidatedTagValues[i];
ExcelWorksheet m;
if (sheetname.Length > 31)
{
m = book.Worksheets.Add(sheetname.Substring(0, 31));
}
else
{
m = book.Worksheets.Add(sheetname);
}
if (sheetname.Length > 31)
{
cells[0, headerTag].Hyperlink.Location = "'" + m.Name.Substring(0, 31) + "'!A1";
cells[0, headerTag].Hyperlink.ToolTip = consolidatedTagValues[i];
cells[0, headerTag].Style = hyperlinkStyle;
cells[0, headerTag].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
cells[0, headerTag].Style.VerticalAlignment = VerticalAlignmentStyle.Center;
}
else
{
cells[0, headerTag].Hyperlink.Location = "'" + m.Name + "'!A1";
cells[0, headerTag].Hyperlink.ToolTip = consolidatedTagValues[i];
cells[0, headerTag].Style = hyperlinkStyle;
cells[0, headerTag].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
cells[0, headerTag].Style.VerticalAlignment = VerticalAlignmentStyle.Center;
}
cells[0, headerTag].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
headerTag++;
}
//set border
var n = worksheet.GetUsedCellRange(true);
n?.Style.Borders.SetBorders(MultipleBorders.Outside, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thick);
int sheetNo = 1;
//filling each sheet
for (int i = 0; i < consolidatedTagValues.Count; i++)
{
var sheet1 = book.Worksheets[sheetNo];
sheet1.Rows[0].Style = book.Styles[BuiltInCellStyleName.Heading4];
sheet1.Rows[0].Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(211, 211, 211), SpreadsheetColor.FromArgb(211, 211, 211));
sheet1.SetDefaultColumnWidth(150, LengthUnit.Pixel);
sheet1.Columns[0].SetWidth(35, LengthUnit.Pixel);
sheet1.Columns[2].SetWidth(50, LengthUnit.Pixel);
sheet1.Columns[3].SetWidth(130, LengthUnit.Pixel);
sheet1.Rows[0].Style.Font.Color = SpreadsheetColor.FromName(ColorName.Black);
sheet1.Columns[0].Style.WrapText = true;
// access CellsCollection of first worksheet
var cellsperSheet = sheet1.Cells;
cellsperSheet["A1"].Value = "S.No";
cellsperSheet["A1"].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet["B1"].Value = "Company Name";
cellsperSheet["B1"].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet["C1"].Value = "Ticker";
cellsperSheet["C1"].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet["D1"].Value = "SectionName";
cellsperSheet["D1"].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet["E1"].Value = "OriginalTag";
cellsperSheet["E1"].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet["F1"].Value = "Disclosure";
cellsperSheet["F1"].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
sheet1.Columns[5].SetWidth(7, LengthUnit.Inch);
sheet1.Columns[1].Style.WrapText = true;
sheet1.Columns[3].Style.WrapText = true;
sheet1.Columns[4].Style.WrapText = true;
sheet1.Columns[5].Style.WrapText = true;
sheet1.Columns[5].Style.VerticalAlignment = VerticalAlignmentStyle.Top;
sheet1.Columns[5].Style.HorizontalAlignment = HorizontalAlignmentStyle.Left;
int serialNo = 0;
int columnC = 0;
int rowC = 0;
foreach (var c in sec10Ks)
{
if (c.SignificantAccountingPolicies.Any(x => x.SourceTagName == consolidatedTagValues[i]))
{
var policydet = c.SignificantAccountingPolicies.First(x => x.SourceTagName == consolidatedTagValues[i]);
rowC++;
serialNo++;
cellsperSheet[rowC, columnC].Value = serialNo;
cellsperSheet[rowC, columnC].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet[rowC, (++columnC)].Value = c.CompanyName;
cellsperSheet[rowC, columnC].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet[rowC, (++columnC)].Value = c.TickerId;
cellsperSheet[rowC, columnC].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet[rowC, (++columnC)].Value = policydet.SectionName;
cellsperSheet[rowC, columnC].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet[rowC, (++columnC)].Value = policydet.OriginalTag;
cellsperSheet[rowC, columnC].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
cellsperSheet[rowC, (++columnC)].Value = policydet.PolicyDescription;
cellsperSheet[rowC, columnC].Style.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Bottom | MultipleBorders.Top | MultipleBorders.Left, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thin);
}
columnC = 0;
}
CellRange? k = sheet1?.GetUsedCellRange(true);
k?.Style.Borders.SetBorders(MultipleBorders.Outside, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Thick);
sheetNo++;
}
return book;
}