我有这段代码而且我不知道如何更改标签中的字体大小和颜色,这应该放在文本文件中。这是我的代码:
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Artikal Kol Prize Sum");
if (Label53.Text == "4")
{
string artikal = Label47.Text;
string Kol = Label45.Text;
string Prize= Label48.Text;
string Sum= Label54.Text;
sw.WriteLine(artikal);
sw.WriteLine(Kol + "X " + Prize+ " " + Sum);
}
答案 0 :(得分:0)
注意:文本文件(如果您的意思是在记事本中打开的扩展名为.txt的文件 例如)没有像font-color或Etc这样的东西。
color
申请font-style
和Attributes
,如下所示。 Label45.Attributes["style"] = "color:red; font-weight:bold;";
但是,上面的代码 - 它没有反映在您的.txt
文件中。
所以 - 你需要 更具体:你的意思是什么文件格式; HTML会很简单, 可能是使用或CSS属性; RTF可以通过使用来实现 RichTextBox控件;设置文本,然后操纵字体等 (如下所示):
richTextBox1.Text = "Some Text";
richTextBox1.SelectAll();
richTextBox1.SelectionFont = new Font("Times New Roman", 20);
richTextBox1.SelectionColor = Color.Aquamarine;
richTextBox1.SaveFile("C:\\restourant.rtf"); // or try with ".doc" file
希望这有帮助,
答案 1 :(得分:0)
尝试使用以下代码
.aspx文件
<asp:Button ID="btnCreateFile" Text="Create File" runat="server"/>
.aspx.cs文件(代码隐藏)
protected void btnCreateFile_Click(object sender, EventArgs e)
{
CreateFile();
}
private void CreateFile()
{
StringBuilder strBody = new StringBuilder();
strBody.Append(@"<html " +
"xmlns:o='urn:schemas-microsoft-com:office:office' " +
"xmlns:w='urn:schemas-microsoft-com:office:word'" +
"xmlns='http://www.w3.org/TR/REC-html40'>" +
"<head><title>Time</title>");
strBody.Append("<!--[if gte mso 9]>" +
"<xml>" +
"<w:WordDocument>" +
"<w:View>Print</w:View>" +
"<w:Zoom>90</w:Zoom>" +
"<w:DoNotOptimizeForBrowser/>" +
"</w:WordDocument>" +
"</xml>" +
"<![endif]-->");
strBody.Append("<style>" +
"<!-- /* Style Definitions */" +
"@page Section1" +
" {size:8.5in 11.0in; " +
" margin:1.0in 1.25in 1.0in 1.25in ; " +
" mso-header-margin:.5in; " +
" mso-footer-margin:.5in; mso-paper-source:0;}" +
" div.Section1" +
" {page:Section1;}" +
"-->" +
"</style></head>");
strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" +
"<div class=Section1>" +
"<h1>Time and tide wait for none</h1>" +
"<p style='color:red'><I>" +
DateTime.Now + "</I></p>" +
"</div></body></html>");
Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader("Content-disposition",
"attachment; filename=mywosrd.doc");
Response.Write(strBody);
}