再次调整

parent 13d40beb
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
namespace Performance.Services.OnlineExcel namespace Performance.Services.OnlineExcel
{ {
public class EpColumn
{
public int row { get; set; }
public int col { get; set; }
public string renderer { get; set; }
}
/// <summary> /// <summary>
/// 单元格Class /// 单元格Class
/// </summary> /// </summary>
...@@ -10,7 +16,8 @@ public class EpCellClass ...@@ -10,7 +16,8 @@ public class EpCellClass
private List<string> _className; private List<string> _className;
public int row { get; set; } public int row { get; set; }
public int col { get; set; } public int col { get; set; }
public string renderer; public bool editor { get; set; }
public string className public string className
{ {
get get
......
namespace Performance.Services.OnlineExcel using System.Collections.Generic;
namespace Performance.Services.OnlineExcel
{ {
/// <summary> /// <summary>
/// 加载Excel汇总信息 /// 加载Excel汇总信息
/// </summary> /// </summary>
public class EpSheet public class EpSheet
{ {
public object renders { get; set; }
public object mergeCells { get; set; } public object mergeCells { get; set; }
public object data { get; set; } public object data { get; set; }
public object cell { get; set; } public object cell { get; set; }
......
...@@ -81,6 +81,9 @@ public List<ExcelSheetInfo> GetExcelSheetName(per_allot allot) ...@@ -81,6 +81,9 @@ public List<ExcelSheetInfo> GetExcelSheetName(per_allot allot)
} }
} }
} }
sheetNames = sheetNames
.OrderBy(w => w.SheetType == SheetType.Unidentifiable ? 1 : 0).ToList();
_cache.Set(key, sheetNames, absoluteExpirationRelativeToNow); _cache.Set(key, sheetNames, absoluteExpirationRelativeToNow);
return sheetNames; return sheetNames;
...@@ -113,6 +116,7 @@ public EpSheet ReadSheet(per_allot allot, string sheetName) ...@@ -113,6 +116,7 @@ public EpSheet ReadSheet(per_allot allot, string sheetName)
List<Dictionary<string, object>> datas = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> datas = new List<Dictionary<string, object>>();
List<EpCellClass> cells = new List<EpCellClass>(); List<EpCellClass> cells = new List<EpCellClass>();
List<EpColumn> renders = new List<EpColumn>();
for (int row = 1, n = sheet.Dimension.End.Row; row <= n; row++) for (int row = 1, n = sheet.Dimension.End.Row; row <= n; row++)
{ {
...@@ -130,6 +134,10 @@ public EpSheet ReadSheet(per_allot allot, string sheetName) ...@@ -130,6 +134,10 @@ public EpSheet ReadSheet(per_allot allot, string sheetName)
var cellStyle = GetCellClass(cell, row, col); var cellStyle = GetCellClass(cell, row, col);
if (cellStyle != null) if (cellStyle != null)
cells.Add(cellStyle); cells.Add(cellStyle);
var render = GetCellRender(cell, row, col);
if (render != null)
renders.Add(render);
} }
datas.Add(data); datas.Add(data);
} }
...@@ -140,6 +148,7 @@ public EpSheet ReadSheet(per_allot allot, string sheetName) ...@@ -140,6 +148,7 @@ public EpSheet ReadSheet(per_allot allot, string sheetName)
cell = cells, cell = cells,
colWidths = colWidths, colWidths = colWidths,
data = datas, data = datas,
renders = renders,
mergeCells = mergeCells, mergeCells = mergeCells,
}; };
_cache.Set(key, epSheet, absoluteExpirationRelativeToNow); _cache.Set(key, epSheet, absoluteExpirationRelativeToNow);
...@@ -201,47 +210,66 @@ private static List<double> GetColWidths(ExcelWorksheet sheet) ...@@ -201,47 +210,66 @@ private static List<double> GetColWidths(ExcelWorksheet sheet)
return colWidths; return colWidths;
} }
/// <summary> /// <summary>
/// 读取类Class /// 读取单元格渲染方式
/// </summary> /// </summary>
/// <param name="cell"></param> /// <param name="cell"></param>
/// <param name="row"></param> /// <param name="row"></param>
/// <param name="col"></param> /// <param name="col"></param>
/// <returns></returns> /// <returns></returns>
private EpCellClass GetCellClass(ExcelRange cell, int row, int col) private EpColumn GetCellRender(ExcelRange cell, int row, int col)
{ {
var cellStyle = new EpCellClass var column = new EpColumn
{ {
row = row - 1, row = row - 1,
col = col - 1 col = col - 1,
}; };
if (cell.Value is ExcelErrorValue) if (cell.Value is ExcelErrorValue)
{ {
cellStyle.renderer = "customExcelErrorValueStylesRenderer"; column.renderer = "customExcelErrorValueStylesRenderer";
} }
else if (!string.IsNullOrEmpty(cell.Formula)) else if (!string.IsNullOrEmpty(cell.Formula))
{ {
cellStyle.renderer = "customFormulaStylesRenderer"; column.renderer = "customFormulaStylesRenderer";
} }
else if (cell.Style.Border.Top.Style != ExcelBorderStyle.None else if (cell.Style.Border.Top.Style != ExcelBorderStyle.None
|| cell.Style.Border.Bottom.Style != ExcelBorderStyle.None || cell.Style.Border.Bottom.Style != ExcelBorderStyle.None
|| cell.Style.Border.Left.Style != ExcelBorderStyle.None || cell.Style.Border.Left.Style != ExcelBorderStyle.None
|| cell.Style.Border.Right.Style != ExcelBorderStyle.None) || cell.Style.Border.Right.Style != ExcelBorderStyle.None)
{ {
cellStyle.renderer = "customExcelBorderStylesRenderer"; column.renderer = "customExcelBorderStylesRenderer";
} }
if (string.IsNullOrEmpty(column.renderer))
if (HorizontalMapps.ContainsKey(cell.Style.HorizontalAlignment.ToString()))
{
cellStyle.AddClassName(HorizontalMapps[cell.Style.HorizontalAlignment.ToString()]);
}
if (VerticalMapps.ContainsKey(cell.Style.VerticalAlignment.ToString()))
{
cellStyle.AddClassName(VerticalMapps[cell.Style.VerticalAlignment.ToString()]);
}
if (string.IsNullOrEmpty(cellStyle.renderer) && string.IsNullOrEmpty(cellStyle.className))
return null; return null;
return column;
}
/// <summary>
/// 读取类Class
/// </summary>
/// <param name="cell"></param>
/// <param name="row"></param>
/// <param name="col"></param>
/// <returns></returns>
private EpCellClass GetCellClass(ExcelRange cell, int row, int col)
{
var cellStyle = new EpCellClass
{
row = row - 1,
col = col - 1,
editor = false
};
//if (HorizontalMapps.ContainsKey(cell.Style.HorizontalAlignment.ToString()))
//{
// cellStyle.AddClassName(HorizontalMapps[cell.Style.HorizontalAlignment.ToString()]);
//}
//if (VerticalMapps.ContainsKey(cell.Style.VerticalAlignment.ToString()))
//{
// cellStyle.AddClassName(VerticalMapps[cell.Style.VerticalAlignment.ToString()]);
//}
cellStyle.AddClassName("htCenter");
cellStyle.AddClassName("htMiddle");
return cellStyle; return cellStyle;
} }
/// <summary> /// <summary>
...@@ -251,7 +279,8 @@ private EpCellClass GetCellClass(ExcelRange cell, int row, int col) ...@@ -251,7 +279,8 @@ private EpCellClass GetCellClass(ExcelRange cell, int row, int col)
/// <returns></returns> /// <returns></returns>
private object GetCellValue(ExcelRange cell) private object GetCellValue(ExcelRange cell)
{ {
return (cell.Value is ExcelErrorValue || !string.IsNullOrEmpty(cell.Formula)) ? cell.Text : cell.Value; //return (cell.Value is ExcelErrorValue || !string.IsNullOrEmpty(cell.Formula)) ? cell.Text : cell.Value;
return cell.Text;
} }
/// <summary> /// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment