コード例 #1
0
        public SearchIP()
        {
            var res = new ListTable();

            urls.ForEachPathsAndSleep(url =>
            {
                HtmlWeb webClient = new HtmlWeb();
                HtmlDocument doc  = webClient.Load(url);

                HtmlNodeCollection headList  = doc.DocumentNode.SelectNodes("//*[@id=\"list\"]/table/thead/tr/th");
                HtmlNodeCollection valueList = doc.DocumentNode.SelectNodes("//*[@id=\"list\"]/table/tbody/tr");

                if (res.Columns.Count == 0)
                {
                    foreach (HtmlNode node in headList)
                    {
                        res.Columns.Add(node.InnerText);
                    }
                }

                foreach (HtmlNode node in valueList)
                {
                    var temp = new List <object>();
                    foreach (HtmlNode child in node.SelectNodes("td"))
                    {
                        temp.Add(child.InnerText);
                    }
                    res.Rows.Add(temp);
                }
            });
            ExcelUtils.ExportToExcel(res.ToDataTable(), "temp.xlsx");
            //File.WriteAllText("temp.txt", JsonHelper.ToJson((JsonData) res, indentLevel: 2));
        }
コード例 #2
0
        public void WriteAllLines(Dictionary <string, string> dic, string path)
        {
            //直接写入excel
            var listTable = new ListTable()
            {
                Rows = dic.Select(p => new List <object>()
                {
                    p.Key, p.Value
                }).ToList(),
                Columns = new List <string>()
                {
                    "key", "value"
                }
            };

            ExcelUtils.ExportToExcel(listTable.ToDataTable(), Path.ChangeExtension(path, ".xlsx"));
        }