| | |
append in word document using c#
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 28
Reputation:
Solved Threads: 0
hello everyone
i have a problem in writing in word document the proble is that i want to append a string after a table i made in that document but it overides it the code is:-
any help would be appreciated
i have a problem in writing in word document the proble is that i want to append a string after a table i made in that document but it overides it the code is:-
C# Syntax (Toggle Plain Text)
//Text to word file StringBuilder strBuilder = newStringBuilder(); strBuilder.Append("<h1 title='Header' align='Center'>Writing To Word Using ASP.NET</h1> ".ToString()); strBuilder.Append("<br>".ToString()); strBuilder.Append("<table align='Center'>".ToString()); strBuilder.Append("<tr>".ToString()); strBuilder.Append("<td style='width:100px;color:green'><b>amiT</b></td>".ToString()); strBuilder.Append("<td style='width:100px;color:red'>India</td>".ToString()); strBuilder.Append("</tr>".ToString()); strBuilder.Append("</table>".ToString()); // string strPath = Request.PhysicalApplicationPath + "\\document\\Test.doc"; string strPath = filename; //string strTextToWrite = TextBox1.Text; FileStream fStream = newFileStream (strPath,FileMode.Append); fStream.Close(); StreamWriter sWriter = newStreamWriter(strPath); sWriter.Write(strBuilder); sWriter.Close();
any help would be appreciated
Last edited by John A; Aug 10th, 2009 at 10:18 pm. Reason: added code tags
•
•
•
•
C# Syntax (Toggle Plain Text)
FileStream fStream = newFileStream (strPath,FileMode.Append); fStream.Close(); StreamWriter sWriter = newStreamWriter(strPath); sWriter.Write(strBuilder); sWriter.Close();
any help would be appreciated
You probably need to seek to the end of the file? It seems like that would be the way to go. The Streamwriter starts at position 0, I think, and just clobbers whatever is there...
Alex Cavnar, aka alc6379
•
•
Join Date: Jul 2009
Posts: 901
Reputation:
Solved Threads: 141
•
•
•
•
C# Syntax (Toggle Plain Text)
FileStream fStream = newFileStream (strPath,FileMode.Append); fStream.Close(); StreamWriter sWriter = newStreamWriter(strPath); sWriter.Write(strBuilder); sWriter.Close();
C# Syntax (Toggle Plain Text)
FileStream fStream = newFileStream (strPath,FileMode.Append); //fStream.Close(); //StreamWriter sWriter = newStreamWriter(strPath); StreamWriter = new StreamWriter(fStream); sWriter.Write(strBuilder); sWriter.Flush(); sWriter.Close();
•
•
Join Date: Jul 2009
Posts: 28
Reputation:
Solved Threads: 0
•
•
•
•
The changes should fix your append at least. Not sure if you are even getting it to compile though.C# Syntax (Toggle Plain Text)
FileStream fStream = newFileStream (strPath,FileMode.Append); //fStream.Close(); //StreamWriter sWriter = newStreamWriter(strPath); StreamWriter = new StreamWriter(fStream); sWriter.Write(strBuilder); sWriter.Flush(); sWriter.Close();
sorry for replying lately
•
•
Join Date: Jul 2009
Posts: 901
Reputation:
Solved Threads: 141
•
•
•
•
actually they did nothing i don,t know why but any way appreciated
sorry for replying lately
I'm not sure if know, but you can append to any file you want. However, that doesn't mean that the reader (MS Word in this case) of the file will understand the data appended.
Anyway, if you will post your code so I can run it on my end, I will help you figure it out.
•
•
Join Date: Jul 2009
Posts: 28
Reputation:
Solved Threads: 0
•
•
•
•
Anyway, if you will post your code so I can run it on my end, I will help you figure it out.
that's my project and it's databases
my code is supposed to make crystal report ,save it as a word document then append some words in that word document
would you just press "save report" in form1.cs then "save " in form2.cs the append code in save menustripitem handler in form2.cs
thanks alot for ur help it's really appreciated
•
•
Join Date: Jul 2009
Posts: 901
Reputation:
Solved Threads: 141
•
•
•
•
thanks alot
that's my project and it's databases
my code is supposed to make crystal report ,save it as a word document then append some words in that word document
would you just press "save report" in form1.cs then "save " in form2.cs the append code in save menustripitem handler in form2.cs
thanks alot for ur help it's really appreciated
I am installing the class library download and will get back to you...
Last edited by DdoubleD; Aug 22nd, 2009 at 1:51 pm. Reason: Found the download
•
•
Join Date: Jul 2009
Posts: 901
Reputation:
Solved Threads: 141
•
•
•
•
i have a problem in writing in word document the proble is that i want to append a string after a table i made in that document but it overides it...
C# Syntax (Toggle Plain Text)
//StreamWriter sWriter = new StreamWriter(fStream); BinaryWriter sWriter = new BinaryWriter(fStream); sWriter.Seek(1, SeekOrigin.End); sWriter.Write("hany}");
What you are dealing with at this point is Word scripting and you need to figure out how you can modify word documents externally or use some library that facilitates doing so, instead of using standard stream writers.
If the word "hany" is all you need appear at the end of the doc, and you wanted it to appear on the same page, you might be able to modify the export options to not fill the entire page with the table, then simply use the quick fix I just gave you.
Does this make sense?
•
•
Join Date: Jul 2009
Posts: 901
Reputation:
Solved Threads: 141
As an after thought, have you considered just adding a field to the end of your report that you can set to text "hany", or whatever, so that when it is exported it will properly format it in the word document? Not sure exactly what you need to do for your project, but a text field in the report or page footer section seems like it might be the way to go.
![]() |
Similar Threads
- Accessing excel worksheet in a word document (VB macro). (Visual Basic 4 / 5 / 6)
- MS word document automaticaly copies a duplicate one every time I open a word documen (Windows NT / 2000 / XP)
- How we open a ms word document file with php? (PHP)
- open a new word document (ASP.NET)
- To read color highlighted text in word document from vb.net (VB.NET)
- How can we print an MS Word document from Java (Java)
- Picture file on a Word document (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: Comparing dates with timespan
- Next Thread: the data in crystal report saved as word document are reversed
| Thread Tools | Search this Thread |
.net access algorithm alignment app array barchart bitmap box broadcast c# c#gridviewcolumn check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datatable datetime degrees development draganddrop drawing elevated encryption enum event excel file focus form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






