国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Word控件Spire.Doc 【Table】教程(6): 在 Word 中合并或拆分表格單元格

這篇具有很好參考價值的文章主要介紹了Word控件Spire.Doc 【Table】教程(6): 在 Word 中合并或拆分表格單元格。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。

Spire.Doc for.NET 最新下載(qun:767755948)https://www.evget.com/product/3368/download

合并單元格是指將兩個或多個單元格組合成一個較大的單元格,而拆分單元格是指將一個單元格分成兩個或多個較小的單元格。在 Microsoft Word 中創(chuàng)建或編輯表格時,您可能經(jīng)常需要合并或拆分表格單元格以更好地呈現(xiàn)數(shù)據(jù)。在本文中,您將學(xué)習(xí)如何使用Spire.Doc for .NET在 C# 和 VB.NET 中合并或拆分 Word 文檔中的表格單元格。

一、安裝適用于 .NET 的 Spire.Doc

首先,您需要添加包含在 Spire.Doc for.NET 包中的 DLL 文件作為您的 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。

PM> Install-Package Spire.Doc

二、使用 C# 和 VB.NET 在 Word 中合并表格單元格

在 Microsoft Word 中,您可以將兩個或多個相鄰的單元格水平或垂直合并為一個更大的單元格。在 Spire.Doc 中,您可以使用Table.ApplyHorizontalMerge()Table.ApplyVerticalMerge()方法實現(xiàn)相同的目的。以下是詳細(xì)步驟:

  • 初始化Document類的一個實例。
  • 使用Document.LoadFromFile()方法加載 Word 文檔。
  • 通過Document.Sections[int]屬性通過索引獲取文檔中的特定部分。
  • 使用Section.AddTable()方法將表格添加到該部分。
  • 使用Table.ResetCells()方法指定表格的行數(shù)和列數(shù)。
  • 使用Table.ApplyHorizontalMerge()方法水平合并表格中的特定單元格。
  • 使用Table.ApplyVerticalMerge()方法垂直合并表格中的特定單元格。
  • 向表中添加一些數(shù)據(jù)。
  • 將樣式應(yīng)用于表格。
  • 使用Document.SaveToFile()方法保存結(jié)果文檔。

【C#】

using Spire.Doc;
using Spire.Doc.Documents;

namespace MergeTableCells
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a Word document
document.LoadFromFile("Input.docx");

//Get the first section
Section section = document.Sections[0];

//Add a 4 x 4 table to the section
Table table = section.AddTable();
table.ResetCells(4, 4);

//Horizontally merge cells 1, 2, 3, and 4 in the first row
table.ApplyHorizontalMerge(0, 0, 3);
//Vertically merge cells 3 and 4 in the first column
table.ApplyVerticalMerge(0, 2, 3);

//Add some data to the table
for (int row = 0; row < table.Rows.Count; row++)
{
for (int col = 0; col < table.Rows[row].Cells.Count; col++)
{
TableCell cell = table[row, col];
cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle;
Paragraph paragraph = cell.AddParagraph();
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center;
paragraph.Text = "Text";
}
}

//Apply a style to the table
table.ApplyStyle(DefaultTableStyle.LightGridAccent1);

//Save the result document
document.SaveToFile("MergeCells.docx", FileFormat.Docx2013);
}
}
}

【VB.NET】

Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace MergeTableCells
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Create a Document instance
Dim document As Document = New Document()
'Load a Word document
document.LoadFromFile("Input.docx")

'Get the first section
Dim section As Section = document.Sections(0)

'Add a 4 x 4 table to the section
Dim table As Table = section.AddTable()
table.ResetCells(4, 4)

'Horizontally merge cells 1, 2, 3, and 4 in the first row
table.ApplyHorizontalMerge(0, 0, 3)
'Vertically merge cells 3 and 4 in the first column
table.ApplyVerticalMerge(0, 2, 3)

'Add some data to the table
For row As Integer = 0 To table.Rows.Count - 1
For col As Integer = 0 To table.Rows(row).Cells.Count - 1
Dim cell As TableCell = table(row, col)
cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
Dim paragraph As Paragraph = cell.AddParagraph()
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
paragraph.Text = "Text"
Next
Next

'Apply a style to the table
table.ApplyStyle(DefaultTableStyle.LightGridAccent1)

'Save the result document
document.SaveToFile("MergeCells.docx", FileFormat.Docx2013)
End Sub
End Class
End Namespace

Word控件Spire.Doc 【Table】教程(6): 在 Word 中合并或拆分表格單元格,Spire.Doc for.net 教程(完),word,microsoft,spire.doc,文檔管理,java

三、使用 C# 和 VB.NET 在 Word 中拆分表格單元格

Spire.Doc for .NET 提供了TableCell.SplitCell()方法,使您能夠?qū)?Word 表格中的一個單元格拆分為兩個或多個單元格。以下是詳細(xì)步驟:

  • 初始化Document類的一個實例。
  • 使用Document.LoadFromFile()方法加載 Word 文檔。
  • 通過Document.Sections[int]屬性通過索引獲取文檔中的特定部分。
  • 通過Section.Tables[int]屬性根據(jù)其索引獲取節(jié)中的特定表。
  • 通過Table.Rows[int].Cells[int]屬性獲取要拆分的表格單元格。
  • 使用TableCell.SplitCell()方法將單元格拆分為特定數(shù)量的列和行。
  • 使用Document.SaveToFile()方法保存結(jié)果文檔。

【C#】

using Spire.Doc;

namespace SplitTableCells
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a Word Document
document.LoadFromFile("MergeCells.docx");

//Get the first section
Section section = document.Sections[0];

//Get the first table in the section
Table table = section.Tables[0] as Table;

//Get the 4th cell in the 4th row
TableCell cell1 = table.Rows[3].Cells[3];
//Split the cell into 2 columns and 2 rows
cell1.SplitCell(2, 2);

//save the result document
document.SaveToFile("SplitCells.docx", FileFormat.Docx2013);
}
}
}

【VB.NET】

Imports Spire.Doc

Namespace SplitTableCells
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Create a Document instance
Dim document As Document = New Document()
'Load a Word Document
document.LoadFromFile("MergeCells.docx")

'Get the first section
Dim section As Section = document.Sections(0)

'Get the first table in the section
Dim table As Table = TryCast(section.Tables(0), Table)

'Get the 4th cell in the 4th row
Dim cell1 As TableCell = table.Rows(3).Cells(3)
'Split the cell into 2 columns and 2 rows
cell1.SplitCell(2, 2)

'save the result document
document.SaveToFile("SplitCells.docx", FileFormat.Docx2013)
End Sub
End Class
End Namespace

Word控件Spire.Doc 【Table】教程(6): 在 Word 中合并或拆分表格單元格,Spire.Doc for.net 教程(完),word,microsoft,spire.doc,文檔管理,java

以上便是如何在 Word 中合并或拆分表格單元格,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。文章來源地址http://www.zghlxwxcb.cn/news/detail-614833.html

到了這里,關(guān)于Word控件Spire.Doc 【Table】教程(6): 在 Word 中合并或拆分表格單元格的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Word控件Spire.Doc 【超鏈接】教程(3):在C#中查找word文檔中的超鏈接

    Word控件Spire.Doc 【超鏈接】教程(3):在C#中查找word文檔中的超鏈接

    Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處

    2024年02月04日
    瀏覽(23)
  • Spire.doc實現(xiàn)對word的操作(包括文字,表格,圖片)

    Spire.doc實現(xiàn)對word的操作(包括文字,表格,圖片)

    Spire.doc比較小眾,因此需要在pom.xml中導(dǎo)入spire.doc的倉庫,導(dǎo)入之后直接導(dǎo)包 導(dǎo)入倉庫后進(jìn)行導(dǎo)包 2.1.1模板 首先需要準(zhǔn)備一個word模板,可以在里面進(jìn)行文字替換,因為文字特別多,所以此處采用了對具有特殊符號的文字進(jìn)行替換。此處采用 ${xxx} 模板如圖所示: 2.1.2替換核心

    2023年04月12日
    瀏覽(33)
  • table表格 ---合并單元格

    table表格 ---合并單元格

    ? ? ? ? 第一種方法 ? ? ? ? ????????利用table的?:header-cell-style屬性 ? ????????第二種方法 ? ? ? ? ? ? ? ? 利用官網(wǎng)提供的el-table-column互相嵌套 ? ? ? ? ? 利用table的:span-method屬性

    2024年02月07日
    瀏覽(20)
  • vxe-table表格合并單元格和編輯

    vxe-table表格合并單元格和編輯

    //這是在vue上面引用vxe-table插件實現(xiàn)的,主要方法都設(shè)置在table中,mergeCells,tableData都是在vue頁面的data初使化數(shù)據(jù), :footer-method=“footerMethod”:尾部數(shù)據(jù),:merge-footer-items=“mergeCells”:尾部合并單元格。vxe-table網(wǎng)址:https://vxetable.cn/#/table/advanced/footerSpan

    2023年04月09日
    瀏覽(39)
  • poi-tl導(dǎo)出word復(fù)雜表格(單元格合并,生成復(fù)雜表格)

    poi-tl導(dǎo)出word復(fù)雜表格(單元格合并,生成復(fù)雜表格)

    官方文檔地址:http://deepoove.com/poi-tl/ 源碼地址:https://github.com/Sayi/poi-tl poi-tl(poi template language)是Word模板引擎,使用Word模板和數(shù)據(jù)創(chuàng)建很棒的Word文檔。 最近在做項目時候有一個關(guān)于導(dǎo)出Word的文件的需求,需要導(dǎo)出的word文件較大,并且格式比較復(fù)雜,使用poi-tl可以很好的

    2024年02月16日
    瀏覽(23)
  • el-table 表格懶加載的同時合并單元格
  • vue中Element-ui 表格 (Table)合并行、列單元格

    vue中Element-ui 表格 (Table)合并行、列單元格

    先在el-table里加個屬性:span-method綁定方法objectSpanMethod(),這個用來把你想合并的列根據(jù)你寫的邏輯來合并,再寫個getSpanArr(),這個寫合并的邏輯。 加一個屬性兩個方法,然后在獲取表格數(shù)據(jù)的時候調(diào)用一下getSpanArr(),示例代碼寫了四個邏輯,根據(jù)id相同合并,根據(jù)id和其他字段

    2024年02月10日
    瀏覽(27)
  • vue前端docx庫生成word表格 并合并單元格的例子

    ????????Vue.js 是一個流行的前端JavaScript框架,用于構(gòu)建用戶界面和單頁應(yīng)用程序。在Vue中生成Word表格并合并單元格,通常需要使用額外的庫,如`docx`,它是一個用于創(chuàng)建和修改Word文檔(`.docx`)的JavaScript庫。 ????????以下是一個使用Vue.js和`docx`庫來生成Word文檔并合并

    2024年02月22日
    瀏覽(48)
  • 基于element-ui的table實現(xiàn)樹級表格操作及單元格合并

    基于element-ui的table實現(xiàn)樹級表格操作及單元格合并

    如題,公司業(yè)務(wù)需求,數(shù)據(jù)結(jié)構(gòu)比較復(fù)雜,需要在一張表內(nèi)實現(xiàn)多級樹狀數(shù)據(jù)展示及同屬性的單元格合并,并在表格內(nèi)實現(xiàn)增刪改操作。 網(wǎng)上翻閱了很多實例,沒有能解決所有需求的案例,于是自己實現(xiàn)了一套。 時間匆忙,邏輯有優(yōu)化的地方還請無償指出! 最終效果如下

    2024年02月14日
    瀏覽(28)
  • 前端vue+elementui導(dǎo)出復(fù)雜(單元格合并,多級表頭)表格el-table轉(zhuǎn)為excel導(dǎo)出

    前端vue+elementui導(dǎo)出復(fù)雜(單元格合并,多級表頭)表格el-table轉(zhuǎn)為excel導(dǎo)出

    需求 :前端對el-table表格導(dǎo)出 插件 : npm install xlsx -S npm install file-saver --save 原理 :直接導(dǎo)出el-table的表格里面的數(shù)據(jù),這樣就會存在缺點,只會導(dǎo)出當(dāng)前頁面的數(shù)據(jù),如果需要導(dǎo)出全部數(shù)據(jù),可以自己重新渲染一個全部數(shù)據(jù)不可見的el-table表格,來導(dǎo)出就可以了 擴(kuò)展 :經(jīng)過

    2024年02月04日
    瀏覽(31)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包