String Manipulation in C#
I am working on c# .net application, and using cry开发者_运维知识库stal reports. I need to print crystal reports on dot matrix printer, but speed of printing is very slow as crystal reports prints in graphical mode. So i moves to dos based printing and use RawPrinter helper class to print it. That works completly fine.
But writing a dataset to a text file(in invoice report format), uses lots of string manipulation for positioning the characters, spacing etc. I use string builder class and padding and lots of if, else to print page totals, grand totals, taxes etc.
Writing a text file in this way is such a pain.
Please suggest me some other feasible and effective approach.
Thanks
You can export the dataset to XML (DataSet.WriteXml
) and transform it to another textual format using XSLT.
You need some sort of templateing engine, but as you are not doing HTML you need the engine to be stand-alone. See C# template engine for some options.
XSLT is a good option if you like XML and already know how to use it, otherwise I would tend to code with a more "code focused" solution.
I had a similar issue and changing printers was not a solution because of 1800 or so clients using dot matrix printers. So solution I came up with was to use a templating engine (StringTemplate http://www.stringtemplate.org/), get the output text file and send it to the printer.
use tabs for everything. it will let you put stuff in tab columns automatically.
精彩评论