Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions PCAxis.Serializers/Excel/CellValueHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;

using ClosedXML.Excel;

namespace PCAxis.Serializers.Excel
{
internal static class CellValueHelper
{
internal static void SetTypedCellValue(IXLCell cell, object value)
{
switch (value)
{
case string s:
cell.SetValue(s);
break;
case bool b:
cell.SetValue(b);
break;
case int i:
cell.SetValue(i);
break;
case long l:
cell.SetValue(l);
break;
case double d:
cell.SetValue(d);
break;
case float f:
cell.SetValue(f);
break;
case decimal m:
cell.SetValue((double)m);
break;
case DateTime dt:
cell.SetValue(dt);
break;
case TimeSpan ts:
cell.SetValue(ts);
break;
default:
cell.SetValue(value?.ToString());
break;
}
}
}
}
2 changes: 1 addition & 1 deletion PCAxis.Serializers/PCAxis.Serializers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="PCAxis.Core" Version="1.3.0" />
<PackageReference Include="PCAxis.Metadata" Version="1.0.5" />
<PackageReference Include="PCAxis.Query" Version="1.0.10" />
<PackageReference Include="ClosedXML" Version="0.97.0" />
<PackageReference Include="ClosedXML" Version="0.105.0" />
<PackageReference Include="PxWeb.Api2.Server.Models" Version="2.3.2" />
<PackageReference Include="Snappier" Version="1.3.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
Expand Down
8 changes: 4 additions & 4 deletions PCAxis.Serializers/Xlsx2Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected virtual void SetCellValue(IXLCell cell, CellContentType type, object v
if (type == CellContentType.Comment)
cell.GetComment().AddText(value.ToString());
else
cell.SetValue(value); //Change from cell.Value = contentInfo to SetValue(..) For not format e.g 10-11 to date
CellValueHelper.SetTypedCellValue(cell, value); // ClosedXML 0.100+ requires concrete value types
}

protected virtual void SetCellFormat(IXLCell cell, CellContentType type, object value, FormatCellDescription changes)
Expand Down Expand Up @@ -141,7 +141,7 @@ private XLWorkbook CreateWorkbook(PCAxis.Paxiom.PXModel model)
// Writes values for the stub and data cells
row = WriteAllRows(row, model, sheet, fmt);

// Writes the information
// Writes the information
WriteAllTableExtraMetadata(row + 1, model, sheet);

return book;
Expand Down Expand Up @@ -233,7 +233,7 @@ private int WriteAllRows(int row, PXModel model, IXLWorksheet sheet, DataFormatt
!value.IsNumeric() ?
(FormatCellDescription)(c => { c.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; })
:
(FormatCellDescription)(c => { c.DataType = XLDataType.Number; c.Style.NumberFormat.Format = FormatNumericCell(GetDecimalPrecision(value, fmt.DecimalSeparator)); })
(FormatCellDescription)(c => { c.Style.NumberFormat.Format = FormatNumericCell(GetDecimalPrecision(value, fmt.DecimalSeparator)); })
);
if (!string.IsNullOrEmpty(n))
{
Expand Down Expand Up @@ -285,7 +285,7 @@ private int WriteAllNotes(int row, PXModel model, IXLWorksheet sheet)
//Writes mandantory contentInfo notes
row = WriteValueNotes(row, model, sheet);

//Writes mandantory cellnotes
//Writes mandantory cellnotes
row = WriteCellNotes(row, model, sheet);
return row;
}
Expand Down
20 changes: 10 additions & 10 deletions PCAxis.Serializers/XlsxSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected virtual void SetCellValue(IXLCell cell, CellContentType type, object v
if (type == CellContentType.Comment)
cell.GetComment().AddText(value.ToString());
else
cell.SetValue(value); //Change from cell.Value = value to SetValue(..) For not format e.g 10-11 to date
CellValueHelper.SetTypedCellValue(cell, value); // ClosedXML 0.100+ requires concrete value types
}

protected virtual void SetCellFormat(IXLCell cell, CellContentType type, object value, FormatCellDescription changes)
Expand All @@ -109,7 +109,7 @@ private XLWorkbook CreateWorkbook(PCAxis.Paxiom.PXModel model)
/*
sheet.Cell(1, 1).Value = model.Meta.Title;
sheet.Cell(1, 1).Style.Font.FontSize = 14;
sheet.Cell(1, 1).Style.Font.Bold = true;
sheet.Cell(1, 1).Style.Font.Bold = true;
*/

setCell(
Expand Down Expand Up @@ -187,7 +187,7 @@ private XLWorkbook CreateWorkbook(PCAxis.Paxiom.PXModel model)
!value.IsNumeric() ?
(FormatCellDescription)(c => { c.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; })
:
(FormatCellDescription)(c => { c.DataType = XLDataType.Number; c.Style.NumberFormat.Format = FormatNumericCell(GetDecimalPrecision(value, fmt.DecimalSeparator)); })
(FormatCellDescription)(c => { c.Style.NumberFormat.Format = FormatNumericCell(GetDecimalPrecision(value, fmt.DecimalSeparator)); })
);
if (!string.IsNullOrEmpty(n))
{
Expand All @@ -202,7 +202,7 @@ private XLWorkbook CreateWorkbook(PCAxis.Paxiom.PXModel model)

if (_showDataNoteCells && !String.IsNullOrEmpty(dataNote))
{
//sheet.Cell(row, column + dataNoteNoteOffset).Value = dataNote;
//sheet.Cell(row, column + dataNoteNoteOffset).Value = dataNote;
setCell(
sheet.Cell(row, column + dataNoteNoteOffset),
CellContentType.DataNote,
Expand Down Expand Up @@ -337,7 +337,7 @@ private int WriteFootnotes(int row, PXModel model, IXLWorksheet sheet)
}
}

//Writes mandantory cellnotes
//Writes mandantory cellnotes
CellNote cn;
VariableValuePair vvp;
for (int i = 0; i < model.Meta.CellNotes.Count; i++)
Expand Down Expand Up @@ -610,7 +610,7 @@ private int WriteTableInformation(int row, PXModel model, IXLWorksheet sheet)
row++;
for (int i = 0; i < str.Length; i++)
{
//sheet.Cell(row++, 2).Value = str[i];
//sheet.Cell(row++, 2).Value = str[i];
setCell(
sheet.Cell(row++, 1),
CellContentType.Info,
Expand Down Expand Up @@ -1087,7 +1087,7 @@ private int WriteTableInformation(int row, PXModel model, IXLWorksheet sheet)
}

//OFFICIAL STATISTICS
//If the statistics are official, insert information about that in the file
//If the statistics are official, insert information about that in the file
//Reqtest error report #406
row++;
if (model.Meta.OfficialStatistics)
Expand Down Expand Up @@ -1158,7 +1158,7 @@ private void WriteHeading(PXModel model, IXLWorksheet sheet)
{
//INTERVAL
int hInterval = CalcPostHeadingInterval(i, model);
//HEADING
//HEADING
p = CalcPreHeadingInterval(i, model); //0;

for (int l = 0; l <= p; l++)
Expand Down Expand Up @@ -1294,7 +1294,7 @@ private void GetStubCell(PXModel model, IXLWorksheet sheet, int stubNr, int rowN
sheet.Cell(row, column),
CellContentType.Code,
val.Code,
c => { c.DataType = XLDataType.Text; c.Style.Font.Bold = true; }
c => { c.Style.Font.Bold = true; }
);
//sheet.Cell(row, column).DataType = XLCellValues.Text;
//sheet.Cell(row, column).Style.Font.Bold = true;
Expand Down Expand Up @@ -1322,7 +1322,7 @@ private void GetStubCell(PXModel model, IXLWorksheet sheet, int stubNr, int rowN
{
/*
sheet.Cell(row, column).Value = val.Text;
sheet.Cell(row, column).Style.Font.Bold = true;
sheet.Cell(row, column).Style.Font.Bold = true;
*/

setCell(
Expand Down
Loading