I'm trying to create a new table in word from a DataTable (sourceTable):
objDoc.tables.A dd(Range:=objDo c.Range, NumRows:=source Table.Rows.Coun t,
NumColumns:=sou rceTable.Column s.Count, DefaultTableBeh avior:=1,
AutoFitBehavior :=0)
Where objDoc is a Word.Document. However I'm always given the error message
"The range cannot be deleted". But I'm not trying to delete a range. I'm
just trying to insert this Table at the caret position in the document.
I'd appreciate any help!
--
Cheers,
elziko 2 2468
Hi,
Try something like this. oWord is the word.applicatio n and odoc is
the word.document.
Dim rows As Integer = ds.Tables(0).Ro ws.Count
Dim columns As Integer = ds.Tables(0).Co lumns.Count
Dim qry As Word.Table 'query table object
Dim rTable As Word.Range = oWord.ActiveDoc ument.Content
qry = oDoc.Tables.Add (rTable, rows, columns)
For c = 1 To columns
For r = 1 To rows
Dim rngData As Word.Range = qry.Cell(r, c).Range
rngData.Text = ds.Tables(0).Ro ws(r - 1).Item(c - 1)
Next
Next
Ken
----------------
"elziko" <el****@NOTSPAM MINGyahoo.co.uk > wrote in message
news:40******** *************** @news.easynet.c o.uk... I'm trying to create a new table in word from a DataTable (sourceTable):
objDoc.tables.A dd(Range:=objDo c.Range, NumRows:=source Table.Rows.Coun t, NumColumns:=sou rceTable.Column s.Count, DefaultTableBeh avior:=1, AutoFitBehavior :=0)
Where objDoc is a Word.Document. However I'm always given the error message "The range cannot be deleted". But I'm not trying to delete a range. I'm just trying to insert this Table at the caret position in the document.
I'd appreciate any help!
--
Cheers,
elziko
Thanks very much for your reply!
For compatibility reasons I am actually using late binding, so here is your
code as I am using it (the code above and below '-------------------- is
what I have added (to just ensure that the table is added to a previously
opened Word instance if once already exists):
Dim objDoc As Object
Dim objWordApp As Object
Try
objWordApp = GetObject(, "Word.Applicati on")
Catch e As Exception
objWordApp = CreateObject("W ord.Application ")
objDoc = objWordApp.Docu ments.Add
End Try
objWordApp.Disp layAlerts = False
If objWordApp.Docu ments.Count < 1 Then
objWordApp.Docu ments.Add()
End If
objDoc = objWordApp.Docu ments(1)
'------------------------------------------------------------------
Dim rows As Integer = sourceTable.Row s.Count
Dim columns As Integer = sourceTable.Col umns.Count
Dim qry As Object
Dim rTable As Object = objWordApp.Acti veDocument.Cont ent
qry = objDoc.Tables.A dd(rTable, rows, columns) '***
For c As Integer = 1 To columns
For r As Integer = 1 To rows
Dim rngData As Object = qry.Cell(r, c).Range
rngData.Text = sourceTable.Row s(r - 1).Item(c - 1)
Next
Next
'------------------------------------------------------------------
objWordApp.Visi ble = True
objWordApp.Wind owState = 0
objWordApp.Acti vate()
objDoc = Nothing
objWordApp = Nothing
However, at runtime I still get the exception telling me that the range
cannot be deleted on the line shown with '***. Do you have any idea why this
may be happening for me and not for you?
--
Cheers,
elziko This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: campwes |
last post by:
Hey, all. I'm trying to develop a C# app that creates Word 2003 mail merge
documents with an Oracle 9i database as the datasource. I used the following
as an example of how I can start out:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;301659
The problem is that the code provided doesn't allow me to add more users to
the mail...
|
by: randi_clausen |
last post by:
Using SQL against a DB2 table the 'with' key word is used to
dynamically create a temporary table with an SQL statement that is
retained for the duration of that SQL statement.
What is the equivalent to the SQL 'with' using TSQL? If there is not
one, what is the TSQL solution to creating a temporary table that is
associated with an SQL...
|
by: David Bradbury |
last post by:
I currently have an iframe on a webpage into which users can insert
content. They can further customise the text as I've included buttons
such as Bold, Italic, Bullet point etc. This is done along the lines
of
<td><div class="cbtn" onClick="cmdExec('bold',idContent)"
onmouseover="button_over(this);" onmouseout="button_out(this);"...
|
by: Jeremy Weiss |
last post by:
Thanks to much help from everyone in my previous thread, I've made it a
pretty fair ways into my billing/invoicing db.
I'm now needing a way to cycle through all the records in a table and create
invoice records for them in another table, but I have no idea where to
begin. Here's the relevant tables:
==============
Table: Customer_tbl
|
by: enak |
last post by:
I have found some code that shows how to convert an html
form to Word. The message said to simply put the following
in the Page_load:
Response.ContentType = "application/ms-word"
Response.AddHeader("content-disposition", "inline;
filename=BP_CaseStatus.doc")
Now all I should have to do is create the page just like I
would if I were...
| |
by: m3ckon |
last post by:
Hi there,
I can succesfully create a word doc from my asp.net page, but I have 2
issues I need to resolve in order to use it in my app:
1) Creating a table: I seem unable to create a table, I'm uing the coe
below, but I'm unsure as to what the Range parameter should be for
oWordDoc.Content.Tables.Add ???
|
by: nish |
last post by:
Hi,
I am struggling with this code. I am trying to create 3 separate
tables and print them in word, however I end up with 1 big table and 1
nested table inside and 1 more nested table within that.
Here is my code..
// CALL CreateTable - see method below
Word.Table oTable = CreateTable();
|
by: outstretchedarm |
last post by:
I'm extremely new to javascript and to programming in general.
I am trying to create an interactive table. I have already created the
table with constants, in the key of C (it is for music). what I would
like to do is to create a dropdown box that would enable the user to
select all 12 keys, then based on that choice, have the whole table...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |