做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

.NET中開(kāi)源文檔操作組件DocX的介紹與使用

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:36:21
文檔

.NET中開(kāi)源文檔操作組件DocX的介紹與使用

.NET中開(kāi)源文檔操作組件DocX的介紹與使用:前言 相信大家應(yīng)該都有所體會(huì),在目前的軟件項(xiàng)目中,都會(huì)較多的使用到對(duì)文檔的操作,用于記錄和統(tǒng)計(jì)相關(guān)業(yè)務(wù)信息。由于系統(tǒng)自身提供了對(duì)文檔的相關(guān)操作,所以在一定程度上極大的簡(jiǎn)化了軟件使用者的工作量。 在.NET項(xiàng)目中如果用戶提出了相關(guān)文檔操作的需求,開(kāi)
推薦度:
導(dǎo)讀.NET中開(kāi)源文檔操作組件DocX的介紹與使用:前言 相信大家應(yīng)該都有所體會(huì),在目前的軟件項(xiàng)目中,都會(huì)較多的使用到對(duì)文檔的操作,用于記錄和統(tǒng)計(jì)相關(guān)業(yè)務(wù)信息。由于系統(tǒng)自身提供了對(duì)文檔的相關(guān)操作,所以在一定程度上極大的簡(jiǎn)化了軟件使用者的工作量。 在.NET項(xiàng)目中如果用戶提出了相關(guān)文檔操作的需求,開(kāi)

前言

相信大家應(yīng)該都有所體會(huì),在目前的軟件項(xiàng)目中,都會(huì)較多的使用到對(duì)文檔的操作,用于記錄和統(tǒng)計(jì)相關(guān)業(yè)務(wù)信息。由于系統(tǒng)自身提供了對(duì)文檔的相關(guān)操作,所以在一定程度上極大的簡(jiǎn)化了軟件使用者的工作量。

在.NET項(xiàng)目中如果用戶提出了相關(guān)文檔操作的需求,開(kāi)發(fā)者較多的會(huì)使用到微軟自行提供的插件,在一定程度上簡(jiǎn)化了開(kāi)發(fā)人員的工作量,但是同時(shí)也給用戶帶來(lái)了一些困擾,例如需要安裝龐大的office,在用戶體驗(yàn)性就會(huì)降低很多,并且在國(guó)內(nèi),很多人都還是使用wps,這就導(dǎo)致一部分只安裝了wps的使用者很是為難,在對(duì)Excel的操作方面,有一個(gè)NPOI組件。那么可能會(huì)有人問(wèn)有沒(méi)有什么辦法讓這些困擾得到解決,答案是肯定的,那就是今天需要介紹的“DocX”組件,接下來(lái)我們就來(lái)了解一下這個(gè)組件的功能和用法。

一.DocX組件概述:

DocX是一個(gè).NET庫(kù),允許開(kāi)發(fā)人員以簡(jiǎn)單直觀的方式處理Word 2007/2010/2013文件。 DocX是快速,輕量級(jí),最好的是它不需要安裝Microsoft Word或Office。DocX組件不僅可以完成對(duì)文檔的一般要求,例如創(chuàng)建文檔,創(chuàng)建表格和文本,并且還可以創(chuàng)建圖形報(bào)表。DocX使創(chuàng)建和操作文檔成為一個(gè)簡(jiǎn)單的任務(wù)。

它不使用COM庫(kù),也不需要安裝Microsoft Office。在使用DocX組件時(shí),你需要安裝為了使用DocX是.NET框架4.0和Visual Studio 2010或更高版本。

   DocX的主要特點(diǎn):

     (1).在文檔中插入,刪除或替換文本。所有標(biāo)準(zhǔn)文本格式都可用。 字體{系列,大小,顏色},粗體,斜體,下劃線,刪除線,腳本{子,超級(jí)},突出顯示。

     (2).段落屬性顯示。方向LeftToRightRightToLeft;縮進(jìn);比對(duì)。  

     (3).DocX也支持:圖片,超鏈接,表,頁(yè)眉和頁(yè)腳,自定義屬性。

  有關(guān)DocX組件的相關(guān)信息就介紹到這里,如果需要更加深入的了解相關(guān)信息,可以進(jìn)入:https://docx.codeplex.com/。

二.DocX相關(guān)類和方法解析:

本文將結(jié)合DocX的源碼進(jìn)行解析,使用.NET Reflector對(duì)DLL文件進(jìn)行反編譯,以此查看源代碼。將DLL文件加入.NET Reflector中,點(diǎn)擊打開(kāi)文件。 

1.DocX.Create() :創(chuàng)建文檔。

public static DocX Create(Stream stream)
{
 MemoryStream stream2 = new MemoryStream();
 PostCreation(ref Package.Open(stream2, FileMode.Create, FileAccess.ReadWrite));
 DocX cx = Load(stream2);
 cx.stream = stream;
 return cx;
}

2.Paragraph.Append:向段落添加信息。

public Paragraph Append(string text)
{
 List<XElement> content = HelperFunctions.FormatInput(text, null);
 base.Xml.Add(content);
 this.runs = base.Xml.Elements(XName.Get("r", DocX.w.NamespaceName)).Reverse<XElement>().Take<XElement>(content.Count<XElement>()).ToList<XElement>();
 return this;
}

public Paragraph Bold()
{
 this.ApplyTextFormattingProperty(XName.Get("b", DocX.w.NamespaceName), string.Empty, null);
 return this;
}

3.Table.InsertTableAfterSelf:將數(shù)據(jù)插入表格。

public override Table InsertTableAfterSelf(int rowCount, int coloumnCount)
{
 return base.InsertTableAfterSelf(rowCount, coloumnCount);
}

public virtual Table InsertTableAfterSelf(int rowCount, int coloumnCount)
{
 XElement content = HelperFunctions.CreateTable(rowCount, coloumnCount);
 base.Xml.AddAfterSelf(content);
 return new Table(base.Document, base.Xml.ElementsAfterSelf().First<XElement>());
}

4.CustomProperty:自定義屬性。

public class CustomProperty
{
 // Fields
 private string name;
 private string type;
 private object value;

 // Methods
 public CustomProperty(string name, bool value);
 public CustomProperty(string name, DateTime value);
 public CustomProperty(string name, double value);
 public CustomProperty(string name, int value);
 public CustomProperty(string name, string value);
 private CustomProperty(string name, string type, object value);
 internal CustomProperty(string name, string type, string value);

 // Properties
 public string Name { get; }
 internal string Type { get; }
 public object Value { get; }
}

5.BarChart:創(chuàng)建棒形圖。

public class BarChart : Chart
{
 // Methods
 public BarChart();
 protected override XElement CreateChartXml();

 // Properties
 public BarDirection BarDirection { get; set; }
 public BarGrouping BarGrouping { get; set; }
 public int GapWidth { get; set; }
}

public abstract class Chart
{
 // Methods
 public Chart();
 public void AddLegend();
 public void AddLegend(ChartLegendPosition position, bool overlay);
 public void AddSeries(Series series);
 protected abstract XElement CreateChartXml();
 public void RemoveLegend();

 // Properties
 public CategoryAxis CategoryAxis { get; private set; }
 protected XElement ChartRootXml { get; private set; }
 protected XElement ChartXml { get; private set; }
 public DisplayBlanksAs DisplayBlanksAs { get; set; }
 public virtual bool IsAxisExist { get; }
 public ChartLegend Legend { get; private set; }
 public virtual short MaxSeriesCount { get; }
 public List<Series> Series { get; }
 public ValueAxis ValueAxis { get; private set; }
 public bool View3D { get; set; }
 public XDocument Xml { get; private set; }
}

6.Chart的AddLegend(),AddSeries(),RemoveLegend()方法解析:

public void AddLegend(ChartLegendPosition position, bool overlay)
{
 if (this.Legend != null)
 {
 this.RemoveLegend();
 }
 this.Legend = new ChartLegend(position, overlay);
 this.ChartRootXml.Add(this.Legend.Xml);
}


public void AddSeries(Series series)
{
 if (this.ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count<XElement>() == this.MaxSeriesCount)
 {
 throw new InvalidOperationException("Maximum series for this chart is" + this.MaxSeriesCount.ToString() + "and have exceeded!");
 }
 this.ChartXml.Add(series.Xml);
}

public void RemoveLegend()
{
 this.Legend.Xml.Remove();
 this.Legend = null;
}

以上是對(duì)DocX組件的一些方法的一些簡(jiǎn)單解析,如果需要知道更多的方法實(shí)現(xiàn)代碼,可自行進(jìn)行下載查看。

三.DocX功能實(shí)現(xiàn)實(shí)例:

1.創(chuàng)建圖表:

 /// <summary>
 /// 創(chuàng)建棒形圖
 /// </summary>
 /// <param name="path">文檔路徑</param>
 /// <param name="dicValue">綁定數(shù)據(jù)</param>
 /// <param name="categoryName">類別名稱</param>
 /// <param name="valueName">值名稱</param>
 /// <param name="title">圖標(biāo)標(biāo)題</param>
 public static bool BarChart(string path,Dictionary<string, ICollection> dicValue,string categoryName,string valueName,string title)
 {
 if (string.IsNullOrEmpty(path))
 {
 throw new ArgumentNullException(path);
 }
 if (dicValue == null)
 {
 throw new ArgumentNullException("dicValue");
 }
 if (string.IsNullOrEmpty(categoryName))
 {
 throw new ArgumentNullException(categoryName);
 }
 if (string.IsNullOrEmpty(valueName))
 {
 throw new ArgumentNullException(valueName);
 }
 if (string.IsNullOrEmpty(title))
 {
 throw new ArgumentNullException(title);
 }
 try
 {
 using (var document = DocX.Create(path))
 {
 //BarChart圖形屬性設(shè)置,BarDirection圖形方向枚舉,BarGrouping圖形分組枚舉
 var c = new BarChart
 {
 BarDirection = BarDirection.Column,
 BarGrouping = BarGrouping.Standard,
 GapWidth = 400
 };
 //設(shè)置圖表圖例位置
 c.AddLegend(ChartLegendPosition.Bottom, false);
 //寫(xiě)入圖標(biāo)數(shù)據(jù)
 foreach (var chartData in dicValue)
 {
 var series = new Series(chartData.Key);
 series.Bind(chartData.Value, categoryName, valueName);
 c.AddSeries(series);
 } 
 // 設(shè)置文檔標(biāo)題
 document.InsertParagraph(title).FontSize(20);
 document.InsertChart(c);
 document.Save();
 return true;
 }

 }
 catch (Exception ex)
 {
 throw new Exception(ex.Message);
 }
 }

2.創(chuàng)建一個(gè)具有超鏈接、圖像和表的文檔。

 /// <summary>
 /// 創(chuàng)建一個(gè)具有超鏈接、圖像和表的文檔。
 /// </summary>
 /// <param name="path">文檔保存路徑</param>
 /// <param name="imagePath">加載的圖片路徑</param>
 /// <param name="url">url地址</param>
 public static void HyperlinksImagesTables(string path,string imagePath,string url)
 {
 if (string.IsNullOrEmpty(path))
 {
 throw new ArgumentNullException(path);
 }
 if (string.IsNullOrEmpty(imagePath))
 {
 throw new ArgumentNullException(imagePath);
 }
 if (string.IsNullOrEmpty(url))
 {
 throw new ArgumentNullException(url);
 }
 try
 {
 using (var document = DocX.Create(path))
 {
 var link = document.AddHyperlink("link", new Uri(url));
 var table = document.AddTable(2, 2);
 table.Design = TableDesign.ColorfulGridAccent2;
 table.Alignment = Alignment.center;
 table.Rows[0].Cells[0].Paragraphs[0].Append("1");
 table.Rows[0].Cells[1].Paragraphs[0].Append("2");
 table.Rows[1].Cells[0].Paragraphs[0].Append("3");
 table.Rows[1].Cells[1].Paragraphs[0].Append("4");
 var newRow = table.InsertRow(table.Rows[1]);
 newRow.ReplaceText("4", "5");
 var image = document.AddImage(imagePath);
 var picture = image.CreatePicture();
 picture.Rotation = 10;
 picture.SetPictureShape(BasicShapes.cube);
 var title = document.InsertParagraph().Append("Test").FontSize(20).Font(new FontFamily("Comic Sans MS"));
 title.Alignment = Alignment.center;
 var p1 = document.InsertParagraph();
 p1.AppendLine("This line contains a ").Append("bold").Bold().Append(" word.");
 p1.AppendLine("Here is a cool ").AppendHyperlink(link).Append(".");
 p1.AppendLine();
 p1.AppendLine("Check out this picture ").AppendPicture(picture).Append(" its funky don't you think?");
 p1.AppendLine();
 p1.AppendLine("Can you check this Table of figures for me?");
 p1.AppendLine();
 p1.InsertTableAfterSelf(table);
 var p2 = document.InsertParagraph();
 p2.AppendLine("Is it correct?");
 document.Save();
 }
 }
 catch (Exception ex)
 {
 throw new Exception(ex.Message);
 }
 
 }

3.將指定內(nèi)容寫(xiě)入文檔:

 /// <summary>
 /// 將指定內(nèi)容寫(xiě)入文檔
 /// </summary>
 /// <param name="path">加載文件路徑</param>
 /// <param name="content">寫(xiě)入文件內(nèi)容</param>
 /// <param name="savePath">保存文件路徑</param>
 public static void ProgrammaticallyManipulateImbeddedImage(string path, string content, string savePath)
 {
 if (string.IsNullOrEmpty(path))
 {
 throw new ArgumentNullException(path);
 }
 if (string.IsNullOrEmpty(content))
 {
 throw new ArgumentNullException(content);
 }
 if (string.IsNullOrEmpty(savePath))
 {
 throw new ArgumentNullException(savePath);
 }
 try
 {
 using (var document = DocX.Load(path))
 {
 // 確保此文檔至少有一個(gè)圖像。
 if (document.Images.Any())
 {
 var img = document.Images[0];
 // 將內(nèi)容寫(xiě)入圖片.
 var b = new Bitmap(img.GetStream(FileMode.Open, FileAccess.ReadWrite));
 //獲取此位圖的圖形對(duì)象,圖形對(duì)象提供繪圖功能。
 var g = Graphics.FromImage(b);
 // 畫(huà)字符串內(nèi)容
 g.DrawString
 (
 content,
 new Font("Tahoma", 20),
 Brushes.Blue,
 new PointF(0, 0)
 );
 // 使用創(chuàng)建\寫(xiě)入流將該位圖保存到文檔中。
 b.Save(img.GetStream(FileMode.Create, FileAccess.Write), ImageFormat.Png);
 }
 else
 {
 document.SaveAs(savePath);
 } 
 }

 }
 catch (Exception ex)
 {
 throw new Exception(ex.Message);
 }
 }

總結(jié)

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

.NET中開(kāi)源文檔操作組件DocX的介紹與使用

.NET中開(kāi)源文檔操作組件DocX的介紹與使用:前言 相信大家應(yīng)該都有所體會(huì),在目前的軟件項(xiàng)目中,都會(huì)較多的使用到對(duì)文檔的操作,用于記錄和統(tǒng)計(jì)相關(guān)業(yè)務(wù)信息。由于系統(tǒng)自身提供了對(duì)文檔的相關(guān)操作,所以在一定程度上極大的簡(jiǎn)化了軟件使用者的工作量。 在.NET項(xiàng)目中如果用戶提出了相關(guān)文檔操作的需求,開(kāi)
推薦度:
標(biāo)簽: 文檔 開(kāi)源 簡(jiǎn)介
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 夏津县| 石台县| 镇康县| 乌海市| 黑河市| 紫金县| 永登县| 株洲县| 东兰县| 汉寿县| 理塘县| 保山市| 银川市| 高唐县| 农安县| 伊春市| 余江县| 合肥市| 诸暨市| 潜山县| 荆门市| 肥西县| 夏河县| 观塘区| 玉门市| 红河县| 韶关市| 云和县| 乐都县| 江西省| 张家口市| 宁强县| 自治县| 卢氏县| 晋江市| 达拉特旗| 五峰| 八宿县| 荔浦县| 靖宇县| 定日县|