|
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 Name
Date 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
|
|
|
|
|
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);<br />
writer.WriteLine(line);<br />
writer.WriteLine();<br />
line = String.Format("Date OF Birth: {0}", dtDateOfBirth.Value.ToString("dd-MMM-yyyy"));<br />
writer.WriteLine(line);<br />
writer.WriteLine();<br />
line = String.Format("Address: {0}", txtAddress.Text);<br />
writer.WriteLine(line);<br />
writer.WriteLine();<br />
writer.WriteLine();<br />
line = String.Format("Education: {0}", txtEducation.Text);<br />
writer.WriteLine(line);<br />
writer.WriteLine();<br />
writer.Flush();
Output file is as,
Name: ASD FGH JKL
Date OF Birth: 30-Feb-2009
Address: Block Number,
Area, City
PinCode
Education: 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
PinCode
Education:
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
Thank you.
I think it is be helpful for me. Provided class has AddImage method too.
I will reply to you, as soon as I complete my task.
Thanks & Regards,
Aniket A. Salunkhe
|
|
|
|
|
Thank you very much.
It is very helpful for me, to generate a file with formatted text & image.
Thanks & Regards,
Aniket A. Salunkhe
|
|
|
|
|
Dear All,
I have created a very basic and simple windows service application using c# in vs 2005.
i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running.
the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created.
this the code bellow
protected override void OnStart(string[] args)
{
System.Windows.Forms.MessageBox.Show("Service is start...");
}
i have googled and used topic in msdn to create window service application.
why the message box does not appear when i am starting the service?
|
|
|
|
|
Services do not show UI. They are logged in as adifferent user and can not display data to a desktop. You can use Trace.Assert(false,"Hello");
Natza Mitzi
|
|
|
|
|
yeah you are right, but if we enable the option "Allow User to Interact with Desktop".
we can show UI to the user.
i have enabled this option through code, still i need to restart my computer to get affected. I want this without restarting the system.
|
|
|
|
|
Instead you can use a client application that interacts with the service.
Using GUI in services is dangerous
Natza Mitzi
|
|
|
|
|
can you please have more detail on client application and the interaction way between client and server application.
you mean i should call window forms from my installer class.
|
|
|
|
|
This is a suggestion of implementation.
The installer should install both service and application. The service should run independently (treated as a server) and the application should run as a client, post requests and run the service to do what it needs to. The connection between the client application can be implemented using .net remoting and the interaction will be transparent. My preferred way is to implement a service and a client application that runs from the system tray using a notify icon. The client application can have the service controller for starting/stopping/pausing/installing/uninstalling the service.
I saw some articles around the code project with samples of notify icons, service controllers and .net remoting. I hope this helps
Natza Mitzi
|
|
|
|
|
Member 6059028 wrote: Allow User to Interact with Desktop
This is VERY bad practice. I believe you can't even do this in Vista.
|
|
|
|
|
You can't display interface components in a Windows service.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You can - you shouldn't, but you can. Windows Services have a property "Interact with desktop" that allows a user to do precisely this - it's yet another crappy design decision.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I know, but I was trying to keep it as simple as possible for the guy.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I am trying to figure out if there's a way I can keep an Excel cell updated as follows:
I have created a C# dll, with a function: double pf2GetPrice(string ticker) which returns the price of a ticker, when calling this function in a cell in Excel - it works nicely.
To keep the cell value current, I'd like to loop within the dll and update the calling cell's value.
Can this be done? (i'm guessing it must be possible)
I've only come across this so far, but its not a very good tutorial: http://msdn.microsoft.com/en-us/library/bb687861.aspx[^]
Any advice would be much appreciated,
G
C# dll newbie
|
|
|
|
|
You are trying to do the work from the wrong end, the loop should logically be in the Excel program. I guess you could have the sheet register itself with the DLL and have a time running to update the sheet (how I have no idea but it may be possible).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why do you think its 'logical' to have the looping in the excel sheet? (to me its more logical to have the dll doing the 'updating' ... leaving the sheet user to not worry about constantly refreshing it.
I'm just thinking about all the dll's out there that keep cell data updated dynamically (bloomberg API for example) ... ?
Therefore I think it must defo be possible
help much appreciated,
g
|
|
|
|
|
Standard OO design, the parent (the dll) has no knowledge of the child (excel). It's like having the web service having to know and keep track of about every subscriber. What happens when you have 2 sheets wanting to get the data from the DLL?
Mind you if the DLL is an abstraction layer between the web service and the excel sheet and is instantiated for each sheet to be serviced then you are right the DLL can do the management. This would give you something like:
Sheet wakes up
Instantiates DLL
DLL gets reference to target cells
DLL starts timer loop
DLL gets data from service (pre difined in DLL)
DLL feeds sheet
DLL repeats
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Ok I see, makes sense yeah
thank you
G
|
|
|
|