Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hellow
i am trying to insert a textbox in word document by c# , i use this code
C#
//rng = oDataDoc.Tables[1].Cell(1, 1).Range;
//wrdApp.ActiveDocument.Shapes.AddTextbox(??,1, 1, 200, 200, ref rng);

i have problem in 1st and last parameter.
a reference to microsoft.office.interop.word already added to my project
in regard to the first parameter it should be
Microsoft.office.Core.MsoTextOrientation
but i could not define this variable in my program
i could write
Microsoft.Office.Interop.Word.
after the last dot in the above line i do not know which one shuold i select
from the listbox being given by the ms visual studio
i need explanation for the 1st and last parameter
Posted

Have a look here:
Shapes.AddTextbox method[^]
first parameter: MsoTextOrientation enumeration[^]
last parameter: Range interface[^]

Below code should works:
C#
Range rng = oDataDoc.Tables[1].Cell(1,1).Range;
Shape sh = oDataDoc.Shapes.AddTextBox(Microsotft.Office.Core.msoTextOrientationHorizontal, 1, 1, 200, 200, ref rng);
 
Share this answer
 
Comments
Engineer khalid 16-Jul-14 16:20pm    
did not works i wrote this
Shape sh = oDataDoc.Shapes.AddTextBox(Microsotft.Office.Core.msoTextOrientationHorizontal, 1, 1, 200, 200, ref rng);
still with error,i added another refrence,it is Office .Net to my project but still
Microsotft.Office.Core.msoTextOrientationHorizontal is unknown to the visual studio
Maciej Los 16-Jul-14 16:33pm    
Try 1 instead of Microsotft.Office.Core.msoTextOrientationHorizontal ;)
Class MsoTextOrientation[^]
Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal
is located in OFFICE .COM NOT OFFICE.NET

THIS WORKS

C#
rng = oDataDoc.Tables[1].Cell(1, 1).Range;
xShape  = oDataDoc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 200, 200, ref rng);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900