Generating formatted file
-
Hi to all, I want to create multiple documents or reports (Word Files or PDF Files) as following format,
Reference No:
Name:
----------- -------------- ---------------
Surname First Name Middle NameDate Of Birth:
I have to fill the content in blan spaces. How I can do above formmating while generating files? In one forum, it is written to use StreamReader & StreamWriter classes to create formatted files. How to use StreamWriter using content of a StreamReader (from a fixed file), to generate new formatted file? Regards, Aniket A. Salunkhe
-
Hi to all, I want to create multiple documents or reports (Word Files or PDF Files) as following format,
Reference No:
Name:
----------- -------------- ---------------
Surname First Name Middle NameDate Of Birth:
I have to fill the content in blan spaces. How I can do above formmating while generating files? In one forum, it is written to use StreamReader & StreamWriter classes to create formatted files. How to use StreamWriter using content of a StreamReader (from a fixed file), to generate new formatted file? Regards, Aniket A. Salunkhe
You can create an rtf file that ms word can read by doing the following: string line; using (StreamWriter writer = File.CreateText(@"C:\file.rtf")) { line = String.Format("Reference No: {0}", 3233); writer.WriteLine(line); writer.WriteLine(); line = String.Format("Name: {0}", "Ron"); writer.WriteLine(line); writer.WriteLine(); //.... writer.Flush(); }
Natza Mitzi
-
You can create an rtf file that ms word can read by doing the following: string line; using (StreamWriter writer = File.CreateText(@"C:\file.rtf")) { line = String.Format("Reference No: {0}", 3233); writer.WriteLine(line); writer.WriteLine(); line = String.Format("Name: {0}", "Ron"); writer.WriteLine(line); writer.WriteLine(); //.... writer.Flush(); }
Natza Mitzi
Thanks for suggestion. With the help of your code, I have wriiten statements as follows,
line = String.Format("Name: {0} {1} {2}", txtLastName.Text, txtMiddleName.Text, txtFirstName.Text); writer.WriteLine(line); writer.WriteLine(); line = String.Format("Date OF Birth: {0}", dtDateOfBirth.Value.ToString("dd-MMM-yyyy")); writer.WriteLine(line); writer.WriteLine(); line = String.Format("Address: {0}", txtAddress.Text); writer.WriteLine(line); writer.WriteLine(); writer.WriteLine(); line = String.Format("Education: {0}", txtEducation.Text); writer.WriteLine(line); writer.WriteLine(); writer.Flush();
Output file is as,Name: ASD FGH JKL
Date OF Birth: 30-Feb-2009
Address: Block Number,
Area, City
PinCodeEducation: Done School in 1999, with % of Marks.
Done PG in 2004 with % of marsk.</But I want output file as with 'Justify' alignement,
Name: ASD FGH JKL
Date OF Birth: 30-Feb-2009
Address:
Block Number,
Area, City
PinCodeEducation:
Done School in 1999, with % of Marks.
Done PG in 2004 with % of marsk.How to do this? Thanks & Regards, Aniket A. Salunkhe
-
Thanks for suggestion. With the help of your code, I have wriiten statements as follows,
line = String.Format("Name: {0} {1} {2}", txtLastName.Text, txtMiddleName.Text, txtFirstName.Text); writer.WriteLine(line); writer.WriteLine(); line = String.Format("Date OF Birth: {0}", dtDateOfBirth.Value.ToString("dd-MMM-yyyy")); writer.WriteLine(line); writer.WriteLine(); line = String.Format("Address: {0}", txtAddress.Text); writer.WriteLine(line); writer.WriteLine(); writer.WriteLine(); line = String.Format("Education: {0}", txtEducation.Text); writer.WriteLine(line); writer.WriteLine(); writer.Flush();
Output file is as,Name: ASD FGH JKL
Date OF Birth: 30-Feb-2009
Address: Block Number,
Area, City
PinCodeEducation: Done School in 1999, with % of Marks.
Done PG in 2004 with % of marsk.</But I want output file as with 'Justify' alignement,
Name: ASD FGH JKL
Date OF Birth: 30-Feb-2009
Address:
Block Number,
Area, City
PinCodeEducation:
Done School in 1999, with % of Marks.
Done PG in 2004 with % of marsk.How to do this? Thanks & Regards, Aniket A. Salunkhe
I am not too familiar with rtf yet I can suggest an alternative (less elegant) solution: You simply add a tab char to your output string: line = String.Format("Address:"); writer.WriteLine(line); line = String.Format("\t{0}", txtAddress1.Text); writer.WriteLine(line); line = String.Format("\t{0}", txtAddress2.Text); writer.WriteLine(line);
Natza Mitzi
-
I am not too familiar with rtf yet I can suggest an alternative (less elegant) solution: You simply add a tab char to your output string: line = String.Format("Address:"); writer.WriteLine(line); line = String.Format("\t{0}", txtAddress1.Text); writer.WriteLine(line); line = String.Format("\t{0}", txtAddress2.Text); writer.WriteLine(line);
Natza Mitzi
Thanks for the suggestion. I tried it. But it is not going to work properly with a Paragraph (from multiple lines textbox). Is there any formatting function availables with StreamWriter? Else do you know how to use macro ( written by Microsoft Word in VB ) in C#? Thanks & Regards, Aniket A. Salunkhe
-
Thanks for the suggestion. I tried it. But it is not going to work properly with a Paragraph (from multiple lines textbox). Is there any formatting function availables with StreamWriter? Else do you know how to use macro ( written by Microsoft Word in VB ) in C#? Thanks & Regards, Aniket A. Salunkhe
I do not have much input on both of your questions. AS far as I know, formatting is done with string.Format and StringBuilder.AppendFormat which formatting wise is the same thing. I can suggest that you check what kind of char to inject to your string (like a paragraph mark) in rtf. I have no experience using office marcos from code. You can look at MS Office Dev Tools or if you are using VS 2008 try an Office add in project. You can also try reposting your question and give the options you are trying (rtf, macro etc.) I am interested in hearing the solution you find. I hope this helps
Natza Mitzi
-
I do not have much input on both of your questions. AS far as I know, formatting is done with string.Format and StringBuilder.AppendFormat which formatting wise is the same thing. I can suggest that you check what kind of char to inject to your string (like a paragraph mark) in rtf. I have no experience using office marcos from code. You can look at MS Office Dev Tools or if you are using VS 2008 try an Office add in project. You can also try reposting your question and give the options you are trying (rtf, macro etc.) I am interested in hearing the solution you find. I hope this helps
Natza Mitzi
Thanks for suggestion.
Natza Mitzi wrote:
You can also try reposting your question and give the options you are trying (rtf, macro etc.) I am interested in hearing the solution you find.
I will do that. Now I am using StreamWriter to create a rtf file as per your suggestion. I have 2 questions, 1. Can I add image using StreamWriter? & How? 2. If now possible to add image using StreamWriter. Can I creat/append a file using existing file which is having some data (for example image)? I tried to add image using StreamWriter, but didn't get any solution. Thanks & Regards, Aniket A. Salunkhe
-
Thanks for suggestion.
Natza Mitzi wrote:
You can also try reposting your question and give the options you are trying (rtf, macro etc.) I am interested in hearing the solution you find.
I will do that. Now I am using StreamWriter to create a rtf file as per your suggestion. I have 2 questions, 1. Can I add image using StreamWriter? & How? 2. If now possible to add image using StreamWriter. Can I creat/append a file using existing file which is having some data (for example image)? I tried to add image using StreamWriter, but didn't get any solution. Thanks & Regards, Aniket A. Salunkhe
Hey, I found an article that seems to be good for you: A class library for RTF processing in C#[^] Checkout the section "RtfDocument class" it seems to be what you are looking for.
Natza Mitzi
-
Hey, I found an article that seems to be good for you: A class library for RTF processing in C#[^] Checkout the section "RtfDocument class" it seems to be what you are looking for.
Natza Mitzi
-
Hey, I found an article that seems to be good for you: A class library for RTF processing in C#[^] Checkout the section "RtfDocument class" it seems to be what you are looking for.
Natza Mitzi