简体   繁体   English

将标签从StringBuilder写入.doc文件aspx.net

[英]write label from StringBuilder to .doc file aspx.net

I need help here.I don't know how to tell to labels from different stringBuilder to go on different .doc files.In my if() statements in need to tell to write labels from first stringBuilder and in another if() statement should write labels from another stingBuilder in another .doc file. 我在这里需要帮助。我不知道如何告诉来自不同的stringBuilder的标签在不同的.doc文件中运行。将另一个stingBuilder中的标签写到另一个.doc文件中。 Below is my code: 以下是我的代码:

          StringBuilder strBody = new StringBuilder();
          StringBuilder strBody1 = 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>");

        strBody1.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("<body lang=EN-US style='tab-interval:.5in'>" +

                                "<p style='color:red; font-size:13px'>" + 
                                Label47.Text +"<br/>" +  
                                Label45.Text +"X   "+
                                Label48.Text +"   " +
                                Label54.Text +"</p>" +
                                "</div></body></html>").Append(strBody1.ToString());


         strBody1.Append("<body lang=EN-US style='tab-interval:.5in'>" +

                                "<p style='color:red; font-size:13px'>" + 
                                Label12.Text +"<br/>" +  
                                Label11.Text +"X   "+
                                Label13.Text +"   " +
                                Label17.Text +"</p>" +
                                "</div></body></html>");



        if (Session["one"] != null && Session["two"] != null && Session["three"] != null)
        {
            {
                string path = @"c:\Backup\kitchen.doc";
                string path2 = @"c:\Backup\bar.doc";

                if (!File.Exists(path) && !File.Exists(path2))
                {
                    using (StreamWriter sw = File.CreateText(path))
                    {

                        using (StreamWriter sw2 = File.CreateText(path2))
                        {

                            if (Label53.Text == "4")
                            {

                                sw.WriteLine(strBody);

                            }

                            else  if (Label53.Text == "1")
                            {
                              sw2.WriteLine(strBody);

                            if (Label44.Text == "4")
                            {

                               sw.WriteLine(strBody1);

                                }

                            else if (Label44.Text == "1")
                            {

                                 sw2.WriteLine(strBody1);

                             }

                        }

I think there is a missing closing } in your if conditions. 我认为您的if条件缺少结束符} The

else  if (Label53.Text == "1")

did not have a closing } 没有结束}

Updated if conditions if条件更新

if (Label53.Text == "4")
{
   sw.WriteLine(strBody);
}
else if (Label53.Text == "1")
{
   sw2.WriteLine(strBody);
}

if (Label44.Text == "4")
{
   sw.WriteLine(strBody1);
}
else if (Label44.Text == "1")
{
   sw2.WriteLine(strBody1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM