【发布时间】:2014-11-08 12:49:23
【问题描述】:
我正在尝试使用Render Snake HTML 库以编程方式为我生成 HTML。我正在尝试使用RenderSnake 制作一个 HTML 表格,如下所示。
PoolName TotalSyncCount TotalAsyncCount SyncNinetyFivePercentile AsyncNinetyFivePercentile
Hello 100 100 4 0
World 300 300 2 0
这里PoolName、TotalSyncCount、TotalAsyncCount、SyncNinetyFivePercentile 和AsyncNinetyFivePercentile 是我的列名。
下面是我可以使用RenderSnake 库创建的示例,它会为我生成 HTML。
public class RendersnakeTest {
public static void main(String[] args) throws IOException {
List<PoolMetrics> poolMetricsList = new ArrayList<>();
poolMetricsList.add(new PoolMetrics("A", "0", "0", "0", "0"));
poolMetricsList.add(new PoolMetrics("A", "1", "1", "1", "1"));
poolMetricsList.add(new PoolMetrics("A", "2", "2", "2", "2"));
poolMetricsList.add(new PoolMetrics("A", "3", "3", "3", "3"));
poolMetricsList.add(new PoolMetrics("A", "4", "4", "4", "4"));
HtmlCanvas html = new HtmlCanvas();
html.html().body().table().tr().th().content("PoolName").th().content("TotalSyncCount").th()
.content("TotalAsyncCount").th().content("SyncNinetyFivePercentile").th()
.content("AsyncNinetyFivePercentile")._tr();
// add the rows
for (PoolMetrics pool : poolMetricsList) {
html.tr()
.td(class_("city-table")).content(pool.getPoolName())
.td().content(pool.getTotalAsyncCount())
.td().content(pool.getTotalSyncCount())
.td().content(pool.getSyncNinetyFivePercentile())
.td().content(pool.getAsyncNinetyFivePercentile())
._tr();
}
// close the table
html._table()._body()._html();
// write the file
final String rendered = html.toHtml();
final File output = new File("c:/output.html");
Files.write(output.toPath(), rendered.getBytes("UTF-8"), StandardOpenOption.TRUNCATE_EXISTING);
// and send out an html email with above table
// so at this moment I would like to have css embedded in my html table so that once I receive html email
// it should have applied css in it
SendEmail.getInstance().sendEmail("abc@host.com", "abc@host.com", "TestSubject", html.toHtml());
}
}
class PoolMetrics {
private String poolName;
private String totalSyncCount;
private String totalAsyncCount;
private String syncNinetyFivePercentile;
private String asyncNinetyFivePercentile;
public PoolMetrics(String poolName, String totalSyncCount, String totalAsyncCount, String syncNinetyFivePercentile, String asyncNinetyFivePercentile) {
this.poolName = poolName;
this.totalSyncCount = totalSyncCount;
this.totalAsyncCount = totalAsyncCount;
this.syncNinetyFivePercentile = syncNinetyFivePercentile;
this.asyncNinetyFivePercentile = asyncNinetyFivePercentile;
}
public String getPoolName() {
return poolName;
}
public String getTotalSyncCount() {
return totalSyncCount;
}
public String getTotalAsyncCount() {
return totalAsyncCount;
}
public String getSyncNinetyFivePercentile() {
return syncNinetyFivePercentile;
}
public String getAsyncNinetyFivePercentile() {
return asyncNinetyFivePercentile;
}
}
问题陈述:
现在我想在上表中应用 CSS,但我不知道如何应用。一般来说,我想使用RenderSnake 库在上表中使用这个CSS。
我无法从他们的文档中了解如何应用 CSS。谁能帮我做这件事?
我无法理解的是我们将 CSS 文件放在哪里,以便它可以在我的桌子上应用那个 CSS,以及我的程序如何知道它必须应用这个 CSS。一般来说,我会将我的表格作为 HTML 电子邮件的一部分发送出去,因此在电子邮件中它应该将所有 CSS 嵌入表格中。
我熟悉 HTML 和 CSS 以及它们的工作原理,但对 RenderSnake 库以及如何使用它感到困惑。
【问题讨论】: