c#動態(tài)生成html,獲取輸入值后生成靜態(tài)網(wǎng)頁

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication2
{
    class PrintBill {

        string name = null;
        List<string> list;

        public PrintBill(string name, List<string> list)//通過構(gòu)造函數(shù)傳入客戶名和商品列表
        {

            this.name = name;
            this.list = list;

        }

        public void ToPrint()
        {
            
            int i=0;
            FileStream fs = new FileStream("../../出貨單-" + name + "-" + DateTime.Now.ToString("yyyy年MM月dd日HH點mm分ss秒")+ ".html", FileMode.Create);//創(chuàng)建一個新的出貨單
            foreach (string str in System.IO.File.ReadAllLines("../../print.html", Encoding.Default)) //讀取出貨單模板
            {
                
                string aline = str;
                aline.Replace("&form["+i+"]$",list[i]);//將占位符替換為輸入的數(shù)據(jù)
                i++;
                byte[] data = System.Text.Encoding.Default.GetBytes(aline);  //獲得字節(jié)數(shù)組
                fs.Write(data, 0, data.Length); //開始寫入
                fs.Flush(); //清空緩沖區(qū)

            }
            fs.Close();//關(guān)閉流
        }

    }
}

-----------------------------------html 模板---------------------------------------------

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>銷售單</title>
</head>
<style type="text/css">
table.gridtable {
    font-family: verdana,arial,sans-serif;
    font-size:15px;
    color:#333333;
    border-width: 1px;
    border-color: #666666;
    border-collapse: collapse;
}
table.gridtable th {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #dedede;
}
table.gridtable td {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #ffffff;
}
</style>
<body>

    <table width="912" height="588" border="1" bordercolor="#000000" class="gridtable">
  <tbody>
    <tr>
      <th height="53" colspan="3" scope="col"  ><strong style="font-size: 18px">商品出貨單 </strong></th>
    </tr>
    <tr>
      <th width="247" height="35" scope="col">客戶名: $form[0]$</th>
      <th width="266" height="35" scope="col">客戶電話:$form[1]$</th>
      <th width="287" height="35" scope="col">日期:$form[2]$</th>
    </tr>
    <tr>
      <th colspan="3" scope="col">&nbsp;$form[6]$</th>
    </tr>
    <tr>
      <th colspan="3" scope="col">&nbsp;$form[7]$</th>
    </tr>
       <tr>
      <th colspan="3" scope="col">&nbsp;$form[8]$</th>
    </tr>
       <tr>
      <th colspan="3" scope="col">&nbsp;$form[9]$</th>
    </tr> <tr>
      <th colspan="3" scope="col">&nbsp;$form[10]$</th>
    </tr> <tr>
      <th colspan="3" scope="col">&nbsp;$form[11]$</th>
    </tr>
       <tr>
      <th colspan="3" scope="col">&nbsp;$form[12]$</th>
    </tr>
       <tr>
      <th colspan="3" scope="col">&nbsp;$form[13]$</th>
    </tr>
       <tr>
      <th height="3" colspan="3" scope="col">&nbsp;$form[14]$</th>
    </tr>
       <tr>
      <th colspan="3" scope="col">&nbsp;$form[15]$</th>
    </tr>
    <tr>
      <th height="39" scope="col">總計:$form[3]$</th>
      <th colspan="2" align="left" scope="col">備注:$form[4]$</th>
    </tr>
       <tr>
      <th height="70" colspan="2" align="left" scope="col">&nbsp;</th>
      <th height="70" align="left" scope="col">&nbsp; 客戶簽字:$form[5]$</th>
    </tr>
  </tbody>
</table>
</body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末胖齐,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖诗眨,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異孕讳,居然都是意外死亡匠楚,警方通過查閱死者的電腦和手機巍膘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來芋簿,“玉大人峡懈,你說我怎么就攤上這事∮虢铮” “怎么了肪康?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長撩穿。 經(jīng)常有香客問我磷支,道長,這世上最難降的妖魔是什么食寡? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任雾狈,我火速辦了婚禮,結(jié)果婚禮上抵皱,老公的妹妹穿的比我還像新娘善榛。我一直安慰自己,他們只是感情好呻畸,可當(dāng)我...
    茶點故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布移盆。 她就那樣靜靜地躺著,像睡著了一般擂错。 火紅的嫁衣襯著肌膚如雪味滞。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天钮呀,我揣著相機與錄音剑鞍,去河邊找鬼。 笑死爽醋,一個胖子當(dāng)著我的面吹牛蚁署,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蚂四,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼光戈,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了遂赠?” 一聲冷哼從身側(cè)響起久妆,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎跷睦,沒想到半個月后筷弦,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年烂琴,在試婚紗的時候發(fā)現(xiàn)自己被綠了爹殊。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,795評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡奸绷,死狀恐怖梗夸,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情号醉,我是刑警寧澤反症,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站扣癣,受9級特大地震影響惰帽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜父虑,卻給世界環(huán)境...
    茶點故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一该酗、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧士嚎,春花似錦呜魄、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至笨蚁,卻和暖如春睹晒,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背括细。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工伪很, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人奋单。 一個月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓锉试,卻偏偏與公主長得像,于是被迫代替她去往敵國和親览濒。 傳聞我的和親對象是個殘疾皇子呆盖,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,724評論 2 354