1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report export. </summary>
public class ReportExport
{
/// <summary> Export to CSV. </summary>
/// <param name="reportResult"> The report result. </param>
/// <returns> A string. </returns>
public string ExportToCsv(ReportResult reportResult)
{
StringBuilder returnValue = new StringBuilder();
returnValue.AppendLine(string.Join(";", reportResult.Headers.Select(s => s.Name.Replace(',', ' ')).ToArray()));
if (reportResult.IsGrouped)
foreach (ReportGroup group in reportResult.Groups)
{
foreach (ReportRow row in reportResult.Rows)
{
returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
}
}
else
foreach (ReportRow row in reportResult.Rows)
{
returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
}
return returnValue.ToString();
}
/// <summary> Export to excel. </summary>
/// <param name="reportResult"> The report result. </param>
/// <returns> A string. </returns>
public string ExportToExcel(ReportResult reportResult)
{
string style = @"<style type='text/css'>
BODY {
font-family: Arial;
font-size: 12px;
}
TABLE {
font-family: Arial;
font-size: 12px;
}
A {
font-family: Arial;
color: #144A86;
font-size: 12px;
cursor: pointer;
text-decoration: none;
font-weight: bold;
}
DIV {
font-family: Arial;
font-size: 12px;
margin-bottom: 0px;
}
P, LI, DIV {
font-size: 12px;
margin-bottom: 0px;
}
P, UL {
font-size: 12px;
margin-bottom: 6px;
margin-top: 0px;
}
H1 {
font-size: 18pt;
}
H2 {
font-weight: bold;
font-size: 14pt;
COLOR: #C0C0C0;
}
H3 {
font-weight: normal;
font-size: 14pt;
text-indent: +1em;
}
H4 {
font-size: 10pt;
font-weight: normal;
}
H5 {
font-size: 10pt;
font-weight: normal;
background: #A9A9A9;
COLOR: white;
display: inline;
}
H6 {
padding: 2 1 2 5;
font-size: 11px;
font-weight: bold;
text-decoration: none;
margin-bottom: 1px;
}
UL {
line-height: 1.5em;
list-style-type: disc;
}
OL {
line-height: 1.5em;
}
LI {
line-height: 1.5em;
}
A IMG {
border: 0;
}
table.gridtable {
color: #333333;
border-width: 0.1pt;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 0.1pt;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable tr {
background-color: #ffffff;
}
table.gridtable td {
border-width: 0.1pt;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>";
string Html = @"<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=8, IE=9, IE=10' />
<meta charset='utf-8'>
<title>Emby Reports Export</title>";
Html += "\n" + style + "\n";
Html += "</head>\n";
Html += "<body>\n";
StringBuilder returnValue = new StringBuilder();
returnValue.AppendLine("<table class='gridtable'>");
returnValue.AppendLine("<tr>");
returnValue.AppendLine(string.Join("", reportResult.Headers.Select(s => string.Format("<th>{0}</th>", s.Name)).ToArray()));
returnValue.AppendLine("</tr>");
if (reportResult.IsGrouped)
foreach (ReportGroup group in reportResult.Groups)
{
returnValue.AppendLine("<tr>");
returnValue.AppendLine("<th scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + (string.IsNullOrEmpty(group.Name) ? " " : group.Name) + "</th>");
returnValue.AppendLine("</tr>");
foreach (ReportRow row in group.Rows)
{
ExportToExcelRow(reportResult, returnValue, row);
}
returnValue.AppendLine("<tr>");
returnValue.AppendLine("<th style='background-color: #ffffff;' scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + " " + "</th>");
returnValue.AppendLine("</tr>");
}
else
foreach (ReportRow row in reportResult.Rows)
{
ExportToExcelRow(reportResult, returnValue, row);
}
returnValue.AppendLine("</table>");
Html += returnValue.ToString();
Html += "</body>";
Html += "</html>";
return Html;
}
private static void ExportToExcelRow(ReportResult reportResult,
StringBuilder returnValue,
ReportRow row)
{
returnValue.AppendLine("<tr>");
returnValue.AppendLine(string.Join("", row.Columns.Select(s => string.Format("<td>{0}</td>", s.Name)).ToArray()));
returnValue.AppendLine("</tr>");
}
}
}
|