You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB
C#

2 months ago
using NetLibrary.ReportPrint;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace NetLibrary.Models
{
public class JsonTable
{
public int ColumnNumber { get; set; }
public List<JsonCell> Cells { get; set; }
public JsonTable()
{
Cells = new List<JsonCell>();
}
public string ExportExcel()
{
DataTable tb = new DataTable();
for (int i = 0; i < ColumnNumber; i++)
{
tb.Columns.Add(new DataColumn() { ColumnName="col"+i });
}
int index = 0;
DataRow row = null;
foreach (var item in Cells)
{
if (index == 0) row = tb.NewRow();
row[index] = item.CellText;
index++;
if (index >= ColumnNumber)
{
index = 0;
tb.Rows.Add(row);
}
}
MicrosoftExcel obj = new MicrosoftExcel();
return obj.Export("",tb);
}
}
public class JsonCell
{
public bool IsHader { get; set; }
public string CellText { get; set; }
}
public class JsonTable<T>
{
public int ColumnNumber { get; set; }
public List<JsonCell<T>> Cells { get; set; }
public JsonTable()
{
Cells = new List<JsonCell<T>>();
}
}
public class JsonCell<T>
{
public bool IsHader { get; set; }
public string CellText { get; set; }
public T ExtModel { get; set; }
}
}