读取所提供的任何数据文件(.txt,.xml,.csv,.excel格式)的报告工具,并以CSV格式创建输出文件 [英] Reporting tool that reads any data files(.txt,.xml,.csv,.excel formats) provided and creates an output file in CSV format
本文介绍了读取所提供的任何数据文件(.txt,.xml,.csv,.excel格式)的报告工具,并以CSV格式创建输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建报告工具,以不同格式读取任何数据文件,并使用控制台应用程序以CSV格式创建输出文件。
How to Create reporting tool that reads any data files in different formats and creates an output file in CSV format using Console application .
推荐答案
一种方法是创建一个抽象基类,包含用于读取文件的方法。
例如:
One approach is to create an abstract base class with methods used to read a file.
For example:
public abstract class FileReaderBase
{
public FileReaderBase()
{
}
public abstract MyOutputFormat Parse(string inputFileName);
}
然后为每个格式创建一个继承自抽象基类的类。
还创建一个输出格式,用于将数据保存在CSV文件中。
Then create a class per format that inherits from the abstract base class.
Also create an output format to be used to save data in a CSV file.
这是一个很大的问题 - 我建议你开始看这个平面文件的便携式高效通用解析器 [ ^ ](和类似的文章)如果你真的想从头开始写一个 - 这并不困难
概念上你需要
b)为解析器实现一个接口,可以将文件类型读入内部格式
c)可选地映射输入字段到所需的输出csv - 不是输入m中的所有字段例如,或者重新排序(我可能使用xml来描述输入文件,映射和输出文件)
d)使用(c)实现csv输出阶段
有'EDI'翻译引擎,例如你所要求的全部/部分 - 但其中许多成本
that's a big question - I'd suggest you start looking at this A Portable and Efficient Generic Parser for Flat Files[^] (and similar articles) if you really want to write one from scratch - its not difficult
Conceptually you need to
a) recognise each type of file
b) implement an Interface for a parser that can read the file type into an internal format
c) optionally map the input fields to the required output csv - not all fields in the input may be used for example, or re-ordered (I'd possibly use xml to describe the input file, mappings, and output file)
d) implement a csv output stage using (c)
there are 'EDI' translate engines for example that do all/some of what your asking - but many of these cost
顺便说一句 - 您是否考虑过像Crystal报告这样的工具或环顾四周找到可以开车/自动化的东西?
btw - have you thought about a tool like Crystal reports or looked around and found something that you can drive/automate ?
这篇关于读取所提供的任何数据文件(.txt,.xml,.csv,.excel格式)的报告工具,并以CSV格式创建输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文