从C#Console应用程序填充HTML? [英] Populate HTML From C# Console App?

查看:76
本文介绍了从C#Console应用程序填充HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有数据,我想用它来填充要打印的表单。我最初的想法是使用HTML模板,以编程方式填充它,然后打印填充的表单。这是以可以轻松读取的方式从数据库打印数据的最佳方法吗?如果是这样,这甚至可以从控制台应用程序?我意识到术语表单和控制台应用程序不混合,但我打算让它成为无人值守的应用程序。

I have data in a database that I would like to use to populate a form to be printed out. My initial thought is to use an HTML template, populate it programatically, and then print the populated form. Is this the best method to print out data from a database in a manner that it can be easily read? If so, is this even possible from a console application? I realize that the terms form and console application do not mix, but I intend to have this be an unattended application.

推荐答案


我在数据库中有数据,我想用它来填充要打印的表单。我最初的想法是使用HTML模板,以编程方式填充它,然后打印填充的表单。这是以可以轻松读取的方式从数据库打印数据的最佳方法吗?如果是这样,这甚至可以从控制台应用程序?我意识到术语表单和控制台应用程序不混合,但我打算让它成为无人值守的应用程序。
I have data in a database that I would like to use to populate a form to be printed out. My initial thought is to use an HTML template, populate it programatically, and then print the populated form. Is this the best method to print out data from a database in a manner that it can be easily read? If so, is this even possible from a console application? I realize that the terms form and console application do not mix, but I intend to have this be an unattended application.



我假设你使用这种机制以比数据库中的表更容易阅读的格式打印出数据库中的所有数据。另一种方法是生成PDF,但我没有看到这比使用HTML模板更有效(如果有的话)。使用HTML(或可能是XML)模板,您的应用程序实际上只需要遍历节点并填充相关节点的innerHTML或innerText,这可以使用XML命名空间中的类来完成。它实际上只是将一个XSL样式表应用于XML,以便在将其发送到打印机之前为其提供漂亮的格式。我没有尝试过在HTML上使用XML类,但考虑到结构密切相关,我猜测它可以毫不费力地工作。

I assume you''re using this mechanism to print out all the data in the database in a more readily readable format than from the tables inside the database. The alternative would be to generate a PDF but I don''t see that this would be much more (if any) efficient than using the HTML template. With an HTML (or probably XML) template, your application really just needs to traverse the nodes and populate the relevant node''s innerHTML or innerText which could be done using classes from the XML namespace. It''s really just a case of applying an XSL stylesheet to the XML to give it a pretty format before sending it to the printer. I''ve not tried using the XML classes on HTML but given that the structure is so closely related, I would hazard a guess that it could be made to work without too much effort.



我假设你使用这种机制以比数据库中的表更容易阅读的格式打印出数据库中的所有数据。另一种方法是生成PDF,但我没有看到这比使用HTML模板更有效(如果有的话)。使用HTML(或可能是XML)模板,您的应用程序实际上只需要遍历节点并填充相关节点的innerHTML或innerText,这可以使用XML命名空间中的类来完成。它实际上只是将一个XSL样式表应用于XML,以便在将其发送到打印机之前为其提供漂亮的格式。我没有尝试过在HTML上使用XML类,但考虑到结构是如此紧密相关,我猜测它可以在没有太多努力的情况下工作。
I assume you''re using this mechanism to print out all the data in the database in a more readily readable format than from the tables inside the database. The alternative would be to generate a PDF but I don''t see that this would be much more (if any) efficient than using the HTML template. With an HTML (or probably XML) template, your application really just needs to traverse the nodes and populate the relevant node''s innerHTML or innerText which could be done using classes from the XML namespace. It''s really just a case of applying an XSL stylesheet to the XML to give it a pretty format before sending it to the printer. I''ve not tried using the XML classes on HTML but given that the structure is so closely related, I would hazard a guess that it could be made to work without too much effort.



我现在倾向于使用XSLT,因为它似乎是最合适的;我有XML文件,我需要以可读的方式使用数据样式。我不知道你对使用XML样式表有多熟悉,但我对语句的价值有疑问。根据我的阅读,样式表应该有一行,例如:


< td>< xsl:value-of select =" XPath">< / td> ;


其中XPath是所需值的适当XPath。目前,当我使用添加的行打开XML文档以包含XSLT时,XPath中不会显示任何值。我是否有可能错过这里的一步?

I am now leaning towards using XSLT given it seems most appropriate; I have XML files and I need the data style in a readable manner. I do not know how familiar you are with using XML stylesheets, but I am having an issue with the value of statement. From what I have read, the stylesheet should hold a line such as:

<td><xsl:value-of select="XPath"></td>

where XPath is the appropriate XPath for the needed value. Currently, when I open the XML document with an added line to include the XSLT, no value is shown from the XPath. Is there a possibility that I might be missing a step here?


无法弄清楚为什么我的xsl:value-of select语句没有返回任何值。


XML文件:


<?xml version =" 1.0" encoding =" ISO-8859-1"?>

<?xml-stylesheet type =" text / xsl" href =" P3A4StyleSheet.xsl"?>


< Pip3A4PurchaseOrderRequest>

< fromRole>

< PartnerRoleDescription> ;

< ContactInformation>

< contactName>

< FreeFormText> Mr。 Smith< / FreeFormText>

< / contactName>

< telephoneNumber>

< CommunicationsNumber> 687-5309< / CommunicationsNumber>

< / telephoneNumber>

< EmailAddress> smith@smith.com< / EmailAddress>

< / ContactInformation>

< / PartnerRoleDescription>

< / fromRole>

< / Pip3A4PurchaseOrderRequest>


样式表:


<?xml version =" 1.0" encoding =" ISO-8859-1"?>


< xsl:stylesheet version =" 2.0" xmlns:xsl =" http:www.w3.org/1999/XSL/Transform">

< xsl:output method =" html"版本= QUOT; 4.0" />


< xsl:template match =" /">

< html>

< ; body>

< h2> ePSA采购订单< / h2>

< table border =" 1">

< ; tr>

< th align =" left"> PO元素< / th>

< th align =" left"> P.O。价值< / th>

< / tr>

< tr>

< td>来自联系人姓名< / td>

< td>< xsl:value-of select =" / Pip3A4PurchaseOrderRequest / fromRole / PartnerRoleDescription / ContactInformation / contactName / FreeFormText" />< / td>

< / tr>

< tr>

< td>来自联系电子邮件< / td>

< td>< xsl:value-of select =" / Pip3A4PurchaseOrderRequest / fromRole / PartnerRoleDescription / ContactInformation / EmailAddress的" />< / td>

< / tr>

< tr>

< td>来自联系电话< / TD>

< td>< xsl:value-of select =" / Pip3A4PurchaseOrderRequest / fromRole / PartnerRoleDescription / ContactInformation / telephoneNumber / CommunicationsNumber" />< / td>

< / tr>

< tr>

< td>杂项< / td>

< td>< xsl:value-of select ="。" />< / td>

< / tr>

< / table>

< / body>

< / html>

< / xsl:template>


< / xsl:stylesheet>
Cannot figure out why my xsl:value-of select statements are not returning any values.

the XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="P3A4StyleSheet.xsl"?>

<Pip3A4PurchaseOrderRequest>
<fromRole>
<PartnerRoleDescription>
<ContactInformation>
<contactName>
<FreeFormText>Mr. Smith</FreeFormText>
</contactName>
<telephoneNumber>
<CommunicationsNumber>687-5309</CommunicationsNumber>
</telephoneNumber>
<EmailAddress>smith@smith.com</EmailAddress>
</ContactInformation>
</PartnerRoleDescription>
</fromRole>
</Pip3A4PurchaseOrderRequest>

The stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http:www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" />

<xsl:template match="/">
<html>
<body>
<h2>ePSA Purchase Order</h2>
<table border="1">
<tr>
<th align="left">P.O. Element</th>
<th align="left">P.O. Value</th>
</tr>
<tr>
<td>From Contact Name</td>
<td><xsl:value-of select="/Pip3A4PurchaseOrderRequest/fromRole/PartnerRoleDescription/ContactInformation/contactName/FreeFormText" /></td>
</tr>
<tr>
<td>From Contact Email</td>
<td><xsl:value-of select="/Pip3A4PurchaseOrderRequest/fromRole/PartnerRoleDescription/ContactInformation/EmailAddress" /></td>
</tr>
<tr>
<td>From Contact Telephone</td>
<td><xsl:value-of select="/Pip3A4PurchaseOrderRequest/fromRole/PartnerRoleDescription/ContactInformation/telephoneNumber/CommunicationsNumber" /></td>
</tr>
<tr>
<td>Misc.</td>
<td><xsl:value-of select="." /></td>
</tr>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


这篇关于从C#Console应用程序填充HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆