是否有电子表格对象/库之类的东西

发布于 2024-09-08 06:51:22 字数 476 浏览 5 评论 0原文

我正在尝试从现有报告中生成一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆流年 2024-09-15 06:51:22

微软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.

别挽留 2024-09-15 06:51:22

我已经用Python和Python编写了这样的。谷歌电子表格 API。该库的界面与您的示例中的界面并不完全相同,但它使用对象来表示工作表和单元格。

即使您是 Python 新手,该库的 API 也非常简单。

首先,您必须将 CSV 上传到 Google 电子表格,然后才能访问它:

# Load the module
import gspread

# Login with your Google account
gc = gspread.login('_your_google_account_email_','password')

# Open a spreadsheet and worksheet
wks = gc.open("name of the spreadsheet").sheet1

wks.update_acell('B2', "it's down there somewhere, let me take another look.")

# Select a range
sales_data = [float(c.value) for c in worksheet.range('E1:E17')]

# Sum it up
sales_total = sum(sales_data)

或者,您可以将 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:

# Load the module
import gspread

# Login with your Google account
gc = gspread.login('_your_google_account_email_','password')

# Open a spreadsheet and worksheet
wks = gc.open("name of the spreadsheet").sheet1

wks.update_acell('B2', "it's down there somewhere, let me take another look.")

# Select a range
sales_data = [float(c.value) for c in worksheet.range('E1:E17')]

# Sum it up
sales_total = sum(sales_data)

Alternatively you can import your CSV data into Excel file and use this wonderful Python library: xlrd

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文