Csharp: Create Excel Workbook or word from a Template File using aspose.Word 14.5 and aspose.Cell 8.1

来源:http://www.cnblogs.com/geovindu/archive/2016/08/04/5736269.html
-Advertisement-
Play Games

winform: webform: https://github.com/asposemarketplace/Aspose_for_OpenXML ...


winform:

/// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenWord_Click(object sender, EventArgs e)
        {

            Dictionary<string, string> dictSource = new Dictionary<string, string>();
            dictSource.Add("NO", "T0001");
            dictSource.Add("INDUSTRY", "捷為工作室");
            dictSource.Add("NAME", "塗聚文");

            string templateFile =("Templates/Templates.doc");
            Aspose.Words.Document doc = new Aspose.Words.Document(templateFile);

            //使用文本方式替換
            foreach (string name in dictSource.Keys)
            {
                doc.Range.Replace(name, dictSource[name], true, true);
            }

            #region 使用書簽替換模式

            Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks["SEX"];
            if (bookmark != null)
            {
                bookmark.Text = "男";
            }
            bookmark = doc.Range.Bookmarks["TEL"];
            if (bookmark != null)
            {
                bookmark.Text = "13824350518*";
            }

            #endregion
            
            doc.Save("testAdvice"+DateTime.Now.ToString("yyyyMMddHHmmssfff")+".docx",Aspose.Words.SaveFormat.Docx);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenExcel_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> dictSource = new Dictionary<string, string>();
            dictSource.Add("NO", "T0001");
            dictSource.Add("INDUSTRY", "捷為工作室");
            dictSource.Add("NAME", "塗聚文");

            string templateFile = ("Templates/Templates.xls");
            WorkbookDesigner designer = new WorkbookDesigner();
            //designer.Workbook.FileName=templateFile;
           Aspose.Cells.Workbook work = new Workbook(templateFile);
           designer.Workbook.Copy(work);   
            Aspose.Cells.Worksheet worksheet = designer.Workbook.Worksheets[0];
            worksheet.Name = "geovindu";
            //使用文本替換
            foreach (string name in dictSource.Keys)
            {
                worksheet.Replace(name, dictSource[name]);
            }

            //使用綁定數據方式替換
            designer.SetDataSource("SEX", "男");
            designer.SetDataSource("TEL", "13824350518*");
            designer.Process();     
            designer.Workbook.Save("testAdvice.xlsx",Aspose.Cells.SaveFormat.Xlsx);
        }

  

webform:

/// <summary>
        /// https://github.com/aspose-words/Aspose.Words-for-.NET
        /// https://asposewords.codeplex.com/
        /// https://asposednn.codeplex.com/
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnGenWord_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> dictSource = new Dictionary<string, string>();
            dictSource.Add("NO", "T0001");
            dictSource.Add("INDUSTRY", "捷為工作室");
            dictSource.Add("NAME", "塗聚文");

            string templateFile = Server.MapPath("./Templates/Templates.doc");
            Aspose.Words.Document doc = new Aspose.Words.Document(templateFile);  //veb: 14.5

            //使用文本方式替換
            foreach (string name in dictSource.Keys)
            {
                doc.Range.Replace(name, dictSource[name], true, true);
            }

            #region 使用書簽替換模式

            Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks["SEX"];
            if (bookmark != null)
            {
                bookmark.Text = "男";
            }
            //書簽方式
            bookmark = doc.Range.Bookmarks["TEL"];
            if (bookmark != null)
            {
                bookmark.Text = "13824350518*";
            }

            #endregion
            string savefile = Server.MapPath("./DuFile/geovindu.docx");
            doc.Save(savefile, Aspose.Words.SaveFormat.Docx);
            Response.Clear();
            Response.Buffer = true;

            //以字元流的形式下載文件     
            string fileName = "geovindu.docx"; //下載文件名稱
            FileStream fs = new FileStream(savefile, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.HeaderEncoding = System.Text.Encoding.UTF8;          
            Response.ContentType = "application/octet-stream";
            //通知瀏覽器下載文件而不是打開     
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            //Response.AddHeader("Content-Length", fs.Length.ToString());
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();



        }
        /// <summary>
        /// http://aspose.github.io/
        /// https://github.com/asposemarketplace/Aspose_for_OpenXML
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> dictSource = new Dictionary<string, string>();
            dictSource.Add("NO", "T0002");
            dictSource.Add("INDUSTRY", "捷為工作室");
            dictSource.Add("NAME", "塗聚文");

            string templateFile = Server.MapPath("./Templates/Templates.xls");
            WorkbookDesigner designer = new WorkbookDesigner();  //Veb:8.1
            Aspose.Cells.Workbook work = new Workbook(templateFile);
            designer.Workbook.Copy(work);   
            //designer.Open(templateFile);

            Aspose.Cells.Worksheet worksheet = designer.Workbook.Worksheets[0];
            worksheet.Name = "geovindu";
            //使用文本替換
            foreach (string name in dictSource.Keys)
            {
                worksheet.Replace(name, dictSource[name]);
            }

            //使用綁定數據方式替換
            designer.SetDataSource("SEX", "男");
            designer.SetDataSource("TEL", "13824350518*");
            designer.Process();
            string savefile = Server.MapPath("./DuFile/geovindu.xlsx");
            designer.Workbook.Save(savefile, Aspose.Cells.SaveFormat.Xlsx);
            string fileName = "geovindu.xlsx"; //下載文件名稱
            FileStream fs = new FileStream(savefile, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.HeaderEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "application/octet-stream";
            //通知瀏覽器下載文件而不是打開     
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            //Response.AddHeader("Content-Length", fs.Length.ToString());
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();


        }

  

 /// <summary>
        /// 提取文檔中的圖片
        /// http://doc.evget.com/HelpDocument/AsposeWordsforNETDocumentationCHM/Aspose.Words.Drawing.Shape.html
        /// </summary>
        public void ExtractImagesToFiles()
        {
            Document doc = new Document("Image.SampleImages.doc");

            NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
            int imageIndex = 0;
            foreach (Shape shape in shapes)
            {
                if (shape.HasImage)
                {
                    string imageFileName = string.Format(
                        "Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType));
                    shape.ImageData.Save(imageFileName);
                    imageIndex++;
                }
            }

            // Newer Microsoft Word documents (such as DOCX) may contain a different type of image container called DrawingML.
            // Repeat the process to extract these if they are present in the loaded document.
            NodeCollection dmlShapes = doc.GetChildNodes(NodeType.DrawingML, true);
            foreach (DrawingML dml in dmlShapes)
            {
                if (dml.HasImage)
                {
                    string imageFileName = string.Format(
                        "Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(dml.ImageData.ImageType));
                    dml.ImageData.Save(imageFileName);
                    imageIndex++;
                }
            }
        }

 

            //同頁連續顯示
            Document dstDoc = new Document("TestFile.Destination.doc");
            Document srcDoc = new Document("TestFile.Source.doc");

            // Make the document appear straight after the destination documents content.
            srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;

            // Append the source document using the original styles found in the source document.
            dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
            dstDoc.Save("TestFile.JoinContinuous Out.doc");


            //另起一頁顯示
            // Set the appended document to start on a new page.
            srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
            // Append the source document using the original styles found in the source document.
            dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
            dstDoc.Save("TestFile.JoinNewPage Out.doc");

  

//實例化一個新的Word Document
            //也可以在Aspose.Words.Document doc = new Aspose.Words.Document(path)中加path參數,

            //此path指向你設計好的Word模板路徑
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            //設置單元格內容對齊方式
            builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
            //清除設置
            builder.PageSetup.ClearFormatting();

            DataTable tbl = new DataTable();

            List<string> list = new List<string>();

            if (tbl != null && tbl.Rows.Count > 0)
            {
                //載入小組
                for (int i = 0; i < tbl.Rows.Count; i++)
                {
                    if (!list.Contains(tbl.Rows[i]["XZ"].ToString()))
                    {
                        list.Add(tbl.Rows[i]["XZ"].ToString());
                    }
                }
                double imgcellwidth = 85;
                double imgcellheight = 120;
                double cellwidth = 165;
                double cellheight = 18.5;
                //匹配小組中的學員
                builder.StartTable();//開始畫Table
                builder.RowFormat.Alignment = Aspose.Words.Tables.RowAlignment.Center;
                string xz = string.Empty;
                int count = 0;
                int rowcount = 0;
                for (int n = 0; n < list.Count; n++)
                {
                    xz = list[n];
                    builder.RowFormat.Height = 20;
                    //插入Table單元格
                    builder.InsertCell();
                    //Table單元格邊框線樣式
                    builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                    //Table此單元格寬度
                    builder.CellFormat.Width = 500;
                    //此單元格中內容垂直對齊方式
                    builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                    builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    //字體大小
                    builder.Font.Size = 11;
                    //是否加粗
                    builder.Bold = true;
                    //向此單元格中添加內容
                    builder.Write(xz);
                    //Table行結束
                    builder.EndRow();
                    builder.Bold = false;
                    DataRow[] rows = tbl.Select("xz='" + xz + "'");
                    for (int i = 0; i < rows.Length; i = i + 2)
                    {
                        count++;
                        rowcount = (count - 1) * 6 + 1 + n;
                        //第一行
                        builder.InsertCell();
                        builder.RowFormat.Height = imgcellheight;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        //合併行單元格
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.CellFormat.TopPadding = 2;
                        builder.CellFormat.WrapText = false;
                        builder.CellFormat.Width = imgcellwidth;
                        if (!string.IsNullOrEmpty(rows[i]["ZPPATH"].ToString()))
                        {
                            //向此單元格中插入圖片
                            Shape shape = new Shape(doc, ShapeType.Image);
                            string url = System.Configuration.ConfigurationManager.AppSettings["UserPhotosSitePath"] + "\\" + rows[i]["ZPPATH"].ToString();
                            shape.ImageData.SetImage(url);
                            shape.Width = imgcellwidth - 2;
                            shape.Height = imgcellheight;
                            shape.HorizontalAlignment = HorizontalAlignment.Center;
                            CompositeNode node = shape.ParentNode;
                            //把此圖片移動到那個單元格中
                            builder.MoveToCell(0, rowcount, 0, 0);
                            builder.InsertNode(shape);
                        }
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = cellwidth;
                        builder.Write(rows[i]["XM"].ToString());
                        builder.InsertCell();
                        builder.RowFormat.Height = imgcellheight;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        //合併行單元格
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.CellFormat.Width = imgcellwidth;
                        if (rows.Length > i + 1)
                        {
                            if (!string.IsNullOrEmpty(rows[i + 1]["ZPPATH"].ToString()))
                            {
                                Shape shape = new Shape(doc, ShapeType.Image);
                                string url = System.Configuration.ConfigurationManager.AppSettings["UserPhotosSitePath"] + "\\" + rows[i + 1]["ZPPATH"].ToString();
                                shape.ImageData.SetImage(url);
                                shape.Width = imgcellwidth - 2;
                                shape.Height = imgcellheight;
                                shape.HorizontalAlignment = HorizontalAlignment.Center;
                                CompositeNode node = shape.ParentNode;
                                builder.MoveToCell(0, rowcount, 2, 0);
                                builder.InsertNode(shape);
                            }
                        }
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = cellwidth;
                        if (rows.Length > i + 1)
                        {
                            builder.Write(rows[i + 1]["XM"].ToString());
                        }
                        builder.EndRow();
                        //第二行
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = cellwidth;
                        builder.Write("單位及職務:" + rows[i]["SZDW"].ToString());
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = cellwidth;
                        if (rows.Length > i + 1)
                        {
                            builder.Write("單位及職務:" + rows[i + 1]["SZDW"].ToString());
                        }
                        builder.EndRow();
                        //第三行
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = cellwidth;
                        builder.Write("單位電話:" + rows[i]["DWDH"].ToString());
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = cellwidth;
                        if (rows.Length > i + 1)
                        {
                            builder.Write("單位電話:" + rows[i + 1]["DWDH"].ToString());
                        }
                        builder.EndRow();
                        //第四行
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = cellwidth;
                        builder.Write("手機:" + rows[i]["SJHM"].ToString());
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = cellwidth;
                        if (rows.Length > i + 1)
                        {
                            builder.Write("手機:" + rows[i + 1]["SJHM"].ToString());
                        }
                        builder.EndRow();
                        //第五行
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = cellwidth;
                        builder.Write("郵編:" + rows[i]["DWYB"].ToString());
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = cellwidth;
                        if (rows.Length > i + 1)
                        {
                            builder.Write("郵編:" + rows[i + 1]["DWYB"].ToString());
                        }
                        builder.EndRow();
                        //第六行
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = cellwidth;
                        builder.Write("Email:" + rows[i]["DZYJ"].ToString());
                        builder.InsertCell();
                        //此單元格與上一行單元格合併
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                        builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Width = imgcellwidth;
                        builder.InsertCell();
                        builder.RowFormat.Height = cellheight;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = cellwidth;
                        if (rows.Length > i + 1)
                        {
                            builder.Write("Email:" + rows[i + 1]["DZYJ"].ToString());
                        }
                        builder.EndRow();
                    }
                }
                builder.EndTable();
            }
            string name = "學員通訊錄.doc";
            //以下載Word的形式打開Wrod
            //如圖所示:
            doc.Save(name, Aspose.Words.SaveFormat.Docx);

  


 https://github.com/asposemarketplace/Aspose_for_OpenXML

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...