是否有电子表格对象/库之类的东西
我正在尝试从现有报告中生成一些 CSV 格式的报告。这些 CSV 文件不仅仅包含数据,还包含报告名称、报告日期、多个数据集 - 每行不一定包含相同数量的字段或每行一致的数据。
我很好奇是否有可用的电子表格类型库,这就是我想象的工作方式。
load some csv file into spreadsheet
report_title = spreadsheet("A1")
report_date = spreadsheet("B2")
sales_data_spreadsheet = spreadsheet("A6:E22)")
sales_total = sales_data_spreadsheet("SUM(E1:E17)")
expenses_data_spreadsheet = spreadsheet("A26:E38")
expenses_total = expenses_data_spreadsheet("SUM(E1:E11")
I'm trying to generate some reporting from existing reports in CSV format. These CSV files don't contain just data, but report name, report date, multiple data sets- each line doesn't necessarily contain the same number of fields or consistent data per row.
I was curious if there was some spreadsheet type library available, this is how I would imagine it to work.
load some csv file into spreadsheet
report_title = spreadsheet("A1")
report_date = spreadsheet("B2")
sales_data_spreadsheet = spreadsheet("A6:E22)")
sales_total = sales_data_spreadsheet("SUM(E1:E17)")
expenses_data_spreadsheet = spreadsheet("A26:E38")
expenses_total = expenses_data_spreadsheet("SUM(E1:E11")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
微软Excel?
您没有电子表格,您已经描述了具有混合格式和一些元数据的平面文件。您的平面文件中的内容表明销售数据位于 A6:E22 中?事实上,A6:E22 在 Microsoft Excel 上下文之外和您的数据上下文中意味着什么?
您可以通过多种方法来处理这些数据,包括亲自解析数据、提供管理数据格式的代码、将其加载到一组数据库表中以及使用 SQL 将其分解。您选择哪个取决于数据是什么、数据来自哪里以及您将如何处理它。如果您提供更多此类信息,可能会更容易推荐一种方法选择。
Microsoft Excel?
You don't have spreadsheets, you have described flat files with mixed formats and some metadata. What in your flat files says that the sales data is in A6:E22? In fact what does A6:E22 mean outside the context of Microsoft Excel and in the context of your data?
There are lots of ways for you to handle this data from parsing it yourself long-hand and supplying code to manage the data formats to loading it into a set of database tables and using SQL to break it into pieces. Which you choose depends on what the data is, where it comes from and what you are going to do with it. If you provide a bit more of that sort of information a choice of approach may be easier to recommend.
我已经用Python和Python编写了这样的库。谷歌电子表格 API。该库的界面与您的示例中的界面并不完全相同,但它使用对象来表示工作表和单元格。
即使您是 Python 新手,该库的 API 也非常简单。
首先,您必须将 CSV 上传到 Google 电子表格,然后才能访问它:
或者,您可以将 CSV 数据导入 Excel 文件并使用这个精彩的 Python 库:xlrd
I've authored such library in Python & Google Spreadsheets API. An interface of the library is not exactly the same as in your example, but it uses objects for sheets and cells representation.
The library's API is pretty straightforward even if you're new to a Python.
First, you have to upload your CSVs into Google Spreadsheets, and then you can access it:
Alternatively you can import your CSV data into Excel file and use this wonderful Python library: xlrd