Files
BeWoPlaner/Service/Core/ExcelDownload.cs

128 lines
3.2 KiB
C#
Raw Permalink Normal View History

2016-06-27 01:45:38 +02:00
using System;
2018-04-27 14:13:42 +02:00
using System.Collections.Generic;
2016-06-27 01:45:38 +02:00
using System.IO;
using System.Text;
namespace BeWo.Service.Core
{
[Serializable]
public class ExcelDownload
{
private string[][] _Content;
private string[] _Header;
public ExcelDownload(string[] pHeader, string[][] pContent)
{
this._Header = pHeader;
this._Content = pContent;
}
public ExcelDownload()
{
}
public string[][] Content
{
get
{
return this._Content;
}
set
{
this._Content = value;
}
}
public string[] Header
{
get
{
return this._Header;
}
set
{
this._Header = value;
}
}
public string CreateExcelOutputString()
{
var lSb = new StringBuilder();
lSb.Append("<HTML xmlns:o=\"urn:schemas-microsoft-com:office:office\">");
lSb.Append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");
lSb.Append("<HEAD>");
lSb.Append("<title></title>");
lSb.Append("<!--[if gte mso 9]><xml>");
lSb.Append("<o:DocumentProperties>");
lSb.Append("<o:Created><%= now %></o:Created>");
lSb.Append("</o:DocumentProperties>");
lSb.Append("</xml><![endif]-->");
lSb.Append("<style>");
lSb.Append(".head { font-weight:bold}");
lSb.Append(".cell, .head { border: thin solid black}");
lSb.Append("</style>");
lSb.Append("</HEAD>");
lSb.Append("<body>");
lSb.Append("<table><tr>");
2018-04-27 14:13:42 +02:00
Dictionary<int, bool> ignoreIndices = new Dictionary<int, bool>();
int index = 0;
2016-06-27 01:45:38 +02:00
foreach (string iHeader in _Header)
{
2018-04-27 14:13:42 +02:00
if (iHeader == "OID")
{
ignoreIndices.Add(index, true);
}
else
{
lSb.Append("<td class=\"head\">");
lSb.Append(iHeader);
lSb.Append("</td>");
}
index++;
2016-06-27 01:45:38 +02:00
}
lSb.Append("</tr>");
2018-04-27 14:13:42 +02:00
2016-06-27 01:45:38 +02:00
foreach (var t in _Content)
{
lSb.Append("<tr>");
2018-04-27 14:13:42 +02:00
index = 0;
2016-06-27 01:45:38 +02:00
foreach (var t1 in t)
{
2018-04-27 14:13:42 +02:00
if (!ignoreIndices.ContainsKey(index))
{
lSb.Append("<td class=\"cell\">");
lSb.Append(t1);
lSb.Append("</td>");
}
index ++;
2016-06-27 01:45:38 +02:00
}
lSb.Append("</tr>");
}
lSb.Append("</table>");
lSb.Append("</body>");
lSb.Append("</HTML>");
return lSb.ToString();
}
}
}