- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 C# 在 Word 文档中添加多个表
// Tables is a list of items which I want to present each in a table
foreach (List<string[]> ClassTable in Tables)
{
// tbl is a "Microsoft.Office.Interop.Word.Table"
// myRange is like MyDoc.Range(ref missing, ref missing)
tbl = MyDoc.Tables.Add(myRange, ClassTable.Count(), 3, missing, missing);
tbl.Borders.Enable = 1;
RowCounter = 1;
foreach (string[] item in TableContent)
{
ColumnCounter = 1;
foreach (string str in item)
{
tbl.Cell(RowCounter, ColumnCounter).Range.Text = str;
ColumnCounter++;
}
RowCounter++;
}
}
此代码仅添加一个表,每当在第二个循环中时,我应该创建另一个表并添加下一个项目值
我尝试通过设置 myRange.start 或 myRange.setRange() ...等来更改范围如果在一张表上创建大量行,则仅添加到文档事件的一张表会失败但不是多表
最佳答案
线路
tbl = MyDoc.Tables.Add(myRange, ClassTable.Count(), 3, missing, missing);
第二次执行时抛出异常,并显示消息“无法删除范围”。此异常被 Word 吞噬,但会停止进一步执行。添加 try/catch 并设置断点会对您有所帮助。
我将您的代码编辑为以下内容以重现并查找引发的异常:
var myRange = Globals.ThisAddIn.Application.ActiveDocument.Range();
foreach (List<List<string>> ClassTable in new List<List<List<string>>> { new List<List<string>> { new List<string> { "A" }, new List<string> { "B" } }, new List<List<string>> { new List<string> { "C" }, new List<string> { "D" } } })
{
// tbl is a "Microsoft.Office.Interop.Word.Table"
// myRange is like MyDoc.Range(ref missing, ref missing)
Microsoft.Office.Interop.Word.Table tbl = null;
try
{
tbl = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add(myRange, ClassTable.Count(), 3);
tbl.Borders.Enable = 1;
int RowCounter = 1;
foreach (var item in ClassTable)
{
int ColumnCounter = 1;
foreach (string str in item)
{
tbl.Cell(RowCounter, ColumnCounter).Range.Text = str;
ColumnCounter++;
}
RowCounter++;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
docs at msdn状态:
Required Range object. The range where you want the table to appear. The table replaces the range, if the range isn't collapsed.
事实证明,您需要通过折叠范围来“移动”到范围的末尾。如果这样做,您将遇到另一个单词问题,即如果文档中有两个紧邻的表格,单词会自动将它们连接到一个表格中。您的固定代码最终会向一个表添加越来越多的行,并不断用值覆盖前几行。所有这些都会导致以下代码应该可以解决您的问题:
var myRange = Globals.ThisAddIn.Application.ActiveDocument.Range();
foreach (List<List<string>> ClassTable in new List<List<List<string>>> { new List<List<string>> { new List<string> { "A" }, new List<string> { "B" } }, new List<List<string>> { new List<string> { "C" }, new List<string> { "D" } } })
{
// tbl is a "Microsoft.Office.Interop.Word.Table"
// myRange is like MyDoc.Range(ref missing, ref missing)
Microsoft.Office.Interop.Word.Table tbl = null;
try
{
tbl = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add(myRange, ClassTable.Count(), 3);
tbl.Borders.Enable = 1;
int RowCounter = 1;
foreach (var item in ClassTable)
{
int ColumnCounter = 1;
foreach (string str in item)
{
tbl.Cell(RowCounter, ColumnCounter).Range.Text = str;
ColumnCounter++;
}
RowCounter++;
}
// Move to the end
myRange.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd);
// Now add something behind the table to prevent word from joining tables into one
myRange.InsertParagraphAfter();
// gosh need to move to the end again
myRange.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
最后一个警告是该段中的第一行内容为:
var myRange = Globals.ThisAddIn.Application.ActiveDocument.Range();
如果文档为空,则向此范围添加表格将起作用,否则它将引发相同的异常,因为在这种情况下我们还没有到达末尾。 .Collapse() 也会在那里解决它。
关于c# - 如何: Adding Multi tables on Word with .网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6996242/
我目前正在制作一个将订阅作为 Multi-Tenancy 应用程序出售的 web 应用程序。我使用的技术是导轨。 但是,它不仅仅是使用当前应用程序的孤立租户。 每个租户创建产品并将其发布到他们的个人应
我们计划将 Azure Service Fabric 用于面向数据的 Multi-Tenancy 应用程序。通常有 100 多个客户,每个客户有 5 - 100 个用户。 查看文档,我得出的结论是,最
我们正在为我们正在构建的自定义 Saas 应用程序评估 Shiro。似乎一个伟大的框架可以完成我们想要的 90% 的工作,开箱即用。我对 Shiro 的理解是基本的,这就是我想要完成的。 我们有多个客
希望使用 NestJS 6 的新请求注入(inject)范围功能实现 Multi-Tenancy NestJS 解决方案。 对于任何给定的服务,我认为我可以做这样的事情: @Injectable({s
我正在寻找一个基于 PHP 的框架,该框架已准备好具有以下功能 1.带有登录/注销的简单仪表板 2. 多个数据库,每个数据库代表一个客户端 只是基本框架。 3.简单的注册支持 用例: 我从 githu
我正在尝试对这个已经回答的问题进行一些跟进...... Service Fabric multi-tenant 如果我要将我的租户设置为 Azure Service Fabric 无状态服务(他们将获
首先,我很清楚 Keycloak 中的多领域 Multi-Tenancy 方法。我接手了一个没有人想到 Multi-Tenancy 的遗留项目。现在,两年后,突然,客户需要这个功能。实际上,微服务已经
我正在使用 Apache Nifi 开发基于云的应用程序,为此我们需要支持 Multi-Tenancy 。但是当前的 Nifi 实现只支持基于角色的用户访问,对于单个流。 我可以理解流状态被保存为 N
对于我积极维护的客户基于 Web 的 CRM 的分支机构数量不断增加的 Multi-Tenancy ,我需要做出一个艰难的数据库设计决策。 我很早就决定为每个分支使用具有单独数据库的单独应用程序,因为
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
很抱歉我的英语不好,希望你能看到我说的。 在Lucene3 Junit测试代码中:org.apache.lucene.queryParser.TestMultiAnalyzer.testMultiAn
假设我们有一个多维数组。 multi[3][10] 那么&multi[0][0]将是multi 如果我们想访问这个数组中的任何元素。我们只需要一次解除引用。因为它位于连续的位置。我无法理解双重取消引用
表结构和示例数据 Wall_Update [INT VARCHAR VARCHAR TIMESTAMP TinyText]
我们需要构建一个软件框架(或中间件),以便在一台机器上运行的不同软件组件(或模块)之间实现消息传递。该框架将提供以下功能: 模块之间的通信是通过“消息传递”。 每个模块都有自己的消息队列和消息处理线程
我正在开发一个在多个域上运行的应用程序。 我想对所有这些都使用 Google 自定义搜索。但是 GCS 需要提供要搜索的网站域。 有没有办法动态指定域?理论上,我可以拥有数千个域,但我不喜欢手动添加所
在 here.com map 类 MapMarker 中,此方法 showInfoBubble () 无法在多 map 标记上显示多信息气泡,对此有任何解决方案吗? 最佳答案 来自 showInfoB
我正在开发一个 Multi-Tenancy 解决方案,我想使用最新的 ASP.NET Identity框架特别是Entity Framework执行。 基本上,我需要允许两个用户使用相同的用户名,尽管
我有 50 台可用台式计算机(配备 i5),每台都运行 Ubuntu 14.04 LTS。我需要通过 C 代码计算某些事件的概率,样本大小至少为 2^45。显然,在一台计算机上运行 C 代码不是一种选
我正在按照页面上的示例进行操作:Multi-input and multi-output models 用于预测新闻标题将收到多少转发和点赞的模型设置。那么 main_output 正在预测有多少
硬件:我们使用 24 核(2*12 核)机器。 SSD 磁盘和 SAS-RAID 0 磁盘有 2 个独立的 Controller 。操作系统:Windows 8.1。超线程已禁用。 软件: 2.1。有
我是一名优秀的程序员,十分优秀!