在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    Word系列之快捷快速表格插入文字圖片

    表格插入圖片文字

    本章節(jié)講述如何在表格中插入圖片和文字,

    Word中的數(shù)據(jù)只有段落和表格;word中表格表示數(shù)據(jù)

    這是單元格內(nèi)容

    代碼如下:

    private void button2_Click(object sender, EventArgs e)

    {

    string fileName = @”HelloWord.docx”;

    using (WordprocessingDocument wd = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))

    {

    var mainDocx = wd.AddMainDocumentPart();

    var docx = new DocumentFormat.OpenXml.Wordprocessing.Document();

    mainDocx.Document = docx;

    var body = mainDocx.Document.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Body());

    //測(cè)試寫入表格

    string[] headerArray = new string[] { “表頭1”, “表頭2”, “表頭3”, “表頭4”, “表頭5”, “表頭6”, “表頭7”, “表頭8”, “表頭9”, “表頭10” };

    List rowList = new List();

    for (int rowI = 0; rowI < 20; rowI++)

    {

    object[] t = new object[headerArray.Length];

    for (int k = 0; k < headerArray.Length; k++)

    {

    if (k < headerArray.Length – 1)

    {

    t[k] = “第” + rowI + “行第” + k + “列”;

    }

    if (k == headerArray.Length – 1)

    {

    string imgFile = “Test_1.jpg”;

    Stream stream = File.OpenRead(imgFile);

    t[k] = stream;

    }

    }

    rowList.Add(t);

    }

    #region 添加文字和圖片表格

    #region 表格

    //表格由 Table、TableRow、TableCell 三級(jí)結(jié)構(gòu)構(gòu)成。那么,向文檔中添加一個(gè) 9 行 x 6 列的表格

    DocumentFormat.OpenXml.Wordprocessing.Table weekTable = body.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Table());

    #region 表格樣式

    TableProperties tabProps = new TableProperties(new TableBorders(

    new TopBorder { Val = new EnumValue(BorderValues.Single), Size = 4, Color = “4F81BD” },

    new BottomBorder

    {

    Val = new EnumValue(BorderValues.Single),

    Size = 4,

    Color = “4F81BD”

    },

    new LeftBorder

    {

    Val = new EnumValue(BorderValues.Single),

    Size = 4,

    Color = “4F81BD”

    },

    new RightBorder

    {

    Val = new EnumValue(BorderValues.Single),

    Size = 4,

    Color = “4F81BD”

    },

    new InsideHorizontalBorder

    {

    Val = new EnumValue(BorderValues.Single),

    Size = 4,

    Color = “4F81BD”

    },

    new InsideVerticalBorder

    {

    Val = new EnumValue(BorderValues.Single),

    Size = 4,

    Color = “4F81BD”

    }

    ));

    #endregion

    weekTable.AppendChild(tabProps);

    var tabWidth = new TableWidth { Width = “5000”, Type = TableWidthUnitValues.Pct };

    weekTable.AppendChild(tabWidth);

    if (headerArray != null && headerArray.Length > 0)

    {

    TableRow tabHeaderRow = weekTable.AppendChild(new TableRow());//設(shè)置列頭行

    foreach (var item in headerArray)

    {

    TableRowProperties tabRowProps = tabHeaderRow.AppendChild(new TableRowProperties(new TableRowHeight { Val = 600, HeightType = HeightRuleValues.Exact }));

    TableCell tabCell = tabHeaderRow.AppendChild(new TableCell());

    Paragraph tabCellPara = tabCell.AppendChild(new Paragraph());

    TableCellProperties tabCellProps = tabCell.AppendChild(new TableCellProperties(new TableCellWidth { Width = “10%”, Type = TableWidthUnitValues.Pct }));

    tabCellPara.AppendChild(new Run(new Text(item)));

    }

    }

    //如果要 Word 能夠正常打開文檔,每個(gè) TableCell 至少需包含一個(gè)空段落才行。

    foreach (object[] rowArray in rowList)

    {

    TableRow tabRow = weekTable.AppendChild(new TableRow());

    TableRowProperties tabRowProps = tabRow.AppendChild(new TableRowProperties(new TableRowHeight { Val = 1500, HeightType = HeightRuleValues.Exact }));

    //列寬可以通過設(shè)置單元格的寬度實(shí)現(xiàn)

    foreach (object objCellValue in rowArray)

    {

    TableCell tabCell = tabRow.AppendChild(new TableCell());

    TableCellProperties tabCellProps;

    tabCellProps = tabCell.AppendChild(new TableCellProperties(new TableCellWidth { Width = “10%”, Type = TableWidthUnitValues.Pct }));

    if (objCellValue == null || objCellValue == DBNull.Value)

    {

    Paragraph tabCellPara = tabCell.AppendChild(new Paragraph());

    tabCellPara.AppendChild(new Run(new Text(“”)));//這里寫入單元格的值

    }

    if (objCellValue != null && objCellValue != DBNull.Value && objCellValue is string)

    {

    Paragraph tabCellPara = tabCell.AppendChild(new Paragraph());

    tabCellPara.AppendChild(new Run(new Text(objCellValue.ToString())));//這里寫入單元格的值

    }

    if (objCellValue != null && objCellValue is Stream)

    {

    string tempRelationId = Guid.NewGuid().ToString().ToUpper();

    AddImageToTableCell(tabCell, tempRelationId);

    }

    }

    }

    #endregion

    #endregion

    }

    Process.Start(fileName);

    }

    public static void AddImageToTableCell(TableCell tableCell, string relationshipId)

    {

    var element =

    new Drawing(

    new DocumentFormat.OpenXml.Drawing.Wordprocessing.Inline(

    new DocumentFormat.OpenXml.Drawing.Wordprocessing.Extent() { Cx = 990000L, Cy = 792000L },

    new DocumentFormat.OpenXml.Drawing.Wordprocessing.EffectExtent()

    {

    LeftEdge = 0L,

    TopEdge = 0L,

    RightEdge = 0L,

    BottomEdge = 0L

    },

    new DocumentFormat.OpenXml.Drawing.Wordprocessing.DocProperties()

    {

    Id = (UInt32Value)1U,

    Name = “Picture1”,

    Title = “圖片標(biāo)題

    },

    new DocumentFormat.OpenXml.Drawing.Wordprocessing.NonVisualGraphicFrameDrawingProperties(

    new DocumentFormat.OpenXml.Drawing.GraphicFrameLocks() { NoChangeAspect = true }),

    new DocumentFormat.OpenXml.Drawing.Graphic(

    new DocumentFormat.OpenXml.Drawing.GraphicData(

    new DocumentFormat.OpenXml.Drawing.Pictures.Picture(

    new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureProperties(

    new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualDrawingProperties()

    {

    Id = (UInt32Value)0U,

    Name = “New Bitmap Image.jpg”

    },

    new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureDrawingProperties()),

    new DocumentFormat.OpenXml.Drawing.Pictures.BlipFill(

    new DocumentFormat.OpenXml.Drawing.Blip(

    new DocumentFormat.OpenXml.Drawing.BlipExtensionList(

    new DocumentFormat.OpenXml.Drawing.BlipExtension()

    {

    Uri =

    “{28A0092B-C50C-407E-A947-70E740481C1C}”

    })

    )

    {

    Embed = relationshipId,

    CompressionState =

    DocumentFormat.OpenXml.Drawing.BlipCompressionValues.Print

    },

    new DocumentFormat.OpenXml.Drawing.Stretch(

    new DocumentFormat.OpenXml.Drawing.FillRectangle())),

    new DocumentFormat.OpenXml.Drawing.Pictures.ShapeProperties(

    new DocumentFormat.OpenXml.Drawing.Transform2D(

    new DocumentFormat.OpenXml.Drawing.Offset() { X = 0L, Y = 0L },

    new DocumentFormat.OpenXml.Drawing.Extents() { Cx = 990000L, Cy = 792000L }),

    new DocumentFormat.OpenXml.Drawing.PresetGeometry(

    new DocumentFormat.OpenXml.Drawing.AdjustValueList()

    )

    { Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle }))

    )

    { Uri = “http://schemas.openxmlformats.org/drawingml/2006/picture” })

    )

    {

    DistanceFromTop = (UInt32Value)0U,

    DistanceFromBottom = (UInt32Value)0U,

    DistanceFromLeft = (UInt32Value)0U,

    DistanceFromRight = (UInt32Value)0U,

    EditId = “50D07946”

    });

    // Append the reference to body, the element should be in a Run.

    tableCell.AppendChild(new Paragraph(new Run(element)));

    }

    鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場(chǎng),版權(quán)歸原作者所有,如有侵權(quán)請(qǐng)聯(lián)系管理員(admin#wlmqw.com)刪除。
    用戶投稿
    上一篇 2022年6月13日 12:09
    下一篇 2022年6月13日 12:10

    相關(guān)推薦

    • 閑魚無貨源怎么賺錢(閑魚無貨源賣什么好)

      如今電商平臺(tái)開店,無貨源模式已經(jīng)成為大家最普遍的開店方式了,而其中閑魚無貨源就是不少人的首選。閑魚無貨源是一個(gè)很適合普通人操作的暴利項(xiàng)目,如果你沒有知識(shí),技能,經(jīng)驗(yàn),資源,就先從閑…

      2022年11月25日
    • 什么是推廣cpa一篇文章帶你看懂CPA推廣渠道

      CPA渠道 CPA指的是按照指定的行為結(jié)算,可以是搜索,可以是注冊(cè),可以是激活,可以是搜索下載激活,可以是綁卡,實(shí)名認(rèn)證,可以是付費(fèi),可以是瀏覽等等。甲乙雙方可以根據(jù)自己的情況來定…

      2022年11月25日
    • 抖音直播帶貨有哪些方法技巧(抖音直播帶貨有哪些痛點(diǎn))

      如今抖音這個(gè)短視頻的變現(xiàn)能力越來越突顯了,尤其是在平臺(tái)上開通直播,更具有超強(qiáng)的帶貨屬性,已經(jīng)有越來越多的普通人加入到其中了。不過直播帶貨雖然很火,但是也不是每個(gè)人都能做好的,那么在…

      2022年11月24日
    • 白襯衫搭配什么褲子好看,女生襯衫穿法圖片

      說起白襯衫和長(zhǎng)褲的搭配組合,不知道大家有沒有發(fā)現(xiàn),雖然是很常見的造型,可不同年齡段慣用的穿搭方式卻不相同,從而也穿出了不同的味道。簡(jiǎn)直是現(xiàn)在這個(gè)季節(jié),時(shí)髦精們的必備造型之一~ 70…

      2022年11月24日
    • 明查|美國(guó)新冠后遺癥患者中有16%癥狀嚴(yán)重以致無法工作?

      點(diǎn)擊進(jìn)入澎湃新聞全球事實(shí)核查平臺(tái) 速覽 – 網(wǎng)傳數(shù)據(jù)比例無權(quán)威信源佐證,該比例有可能是結(jié)合了美國(guó)疾病防控中心和布魯金斯學(xué)會(huì)的數(shù)據(jù)得出,但這兩個(gè)機(jī)構(gòu)的調(diào)研目的和樣本都不同…

      2022年11月24日
    • 寬帶測(cè)速軟件(手機(jī)寬帶測(cè)速軟件)

      中國(guó)聯(lián)通用戶可登錄中國(guó)聯(lián)通網(wǎng)上營(yíng)業(yè)廳,選擇寬帶寬帶服務(wù)寬帶測(cè)速,按頁(yè)面指導(dǎo)進(jìn)行測(cè)速,測(cè)速時(shí)建議您直連電腦,如測(cè)速結(jié)果無法達(dá)到簽約速率,您可通過中國(guó)聯(lián)通APP,“服務(wù)報(bào)障在線報(bào)障”進(jìn)…

      2022年11月22日
    • 鬼的圖片(鬼的圖片 頭像)

      今天小編給各位分享鬼的圖片的知識(shí),其中也會(huì)對(duì)鬼的圖片 頭像進(jìn)行解釋,如果能碰巧解決你現(xiàn)在面臨的問題,別忘了關(guān)注本站,現(xiàn)在開始吧! 鬼長(zhǎng)什么樣子呀?(發(fā)圖片來) 鬼很可怕的,要裁圖片…

      2022年11月22日
    • 馬斯克凌晨一點(diǎn)半曬“代碼審查”現(xiàn)場(chǎng),編排他的段子比瘋狂星期四還多

      夢(mèng)晨 Pine 發(fā)自 凹非寺 量子位 | 公眾號(hào) QbitAI 每一個(gè)真正會(huì)寫代碼的人,請(qǐng)?jiān)谙挛?點(diǎn)到總部10層報(bào)到。 每一個(gè)真正會(huì)寫代碼的人,請(qǐng)?jiān)谙挛?點(diǎn)到總部10層報(bào)到。 馬斯…

      2022年11月21日
    • 淘寶運(yùn)營(yíng)數(shù)據(jù)分析的3個(gè)指標(biāo)解析(運(yùn)營(yíng)數(shù)據(jù)分析怎么做)

      我們知道淘寶運(yùn)營(yíng)工作中對(duì)于數(shù)據(jù)的分析與整理是很重要的,這些工作乍一聽可能比較難,但是也有一些相關(guān)的技巧可以讓我們能夠有效的找出對(duì)我們有用的數(shù)據(jù),這樣我們也能夠更加直觀的看出我們店鋪…

      2022年11月20日
    • 展字的各種寫法圖片(展筆順什么意思)

      昨天我們講解了上展下收,今天我們講解上收下展,看過昨天文章內(nèi)容的朋友,對(duì)今天所講的內(nèi)容應(yīng)該不難理解。 結(jié)構(gòu)八:上收下展。 簡(jiǎn)單來說就是上邊部分的筆畫收縮,下邊部分筆畫舒展。詳細(xì)講解…

      2022年11月19日

    聯(lián)系我們

    聯(lián)系郵箱:admin#wlmqw.com
    工作時(shí)間:周一至周五,10:30-18:30,節(jié)假日休息