Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Tue Dec 28, 2010 7:02 am
Hello,
can you tell me how to know whether a Word document contains tables?
-
moonsky
-
- Posts: 9
- Joined: Mon Dec 13, 2010 7:39 am
Tue Dec 28, 2010 8:56 am
if you want to do so, you can follow the codes:
Document document = new Document("Sample.doc");
IList<IDocumentObject> nodes = GetAllObjects(document);
foreach (IDocumentObject node in nodes)
{
if (node.DocumentObjectType == DocumentObjectType.Table)
{
Table tableNode = node as Table;
Console.WriteLine(tableNode.TableFormat);
}
}
private static IList<IDocumentObject> GetAllObjects(Document document)
{
List<IDocumentObject> nodes = new List<IDocumentObject>();
Queue<ICompositeObject> containers = new Queue<ICompositeObject>();
containers.Enqueue(document);
while (containers.Count > 0)
{
ICompositeObject container = containers.Dequeue();
DocumentObjectCollection docObjects = container.ChildObjects;
foreach (DocumentObject docObject in docObjects)
{
nodes.Add(docObject);
if (docObjects is ICompositeObject)
{
containers.Enqueue(docObjects as ICompositeObject);
}
}
}
return nodes;
}
e-iceblue support
-
iceblue support
-
- Posts: 240
- Joined: Tue Dec 21, 2010 2:56 am
Tue Mar 08, 2011 2:13 pm
Hello,
when I use this code it only gives the output "Type: Section" instead of searching for tables. Is here something missing?
-
pbernhardt
-
- Posts: 11
- Joined: Thu Mar 03, 2011 1:55 pm
Fri Mar 11, 2011 3:57 am
Hi,
That code just a sample, not a full demo. You may need a method like:
- Code: Select all
public bool ContainsTable(Document doc)
{
IList<IDocumentObject> nodes = GetAllObjects(document);
foreach (IDocumentObject node in nodes)
{
if (node.DocumentObjectType == DocumentObjectType.Table)
{
return true;
}
}
}
Harry
Technical Support / Developer,
e-iceblue Support Team
-
harry.support
-
- Posts: 180
- Joined: Mon Nov 08, 2010 3:11 pm