在 PHP/Mysql 中处理动态 CSV 标题

发布于 2024-11-02 22:33:04 字数 437 浏览 1 评论 0原文

我知道标题不是最具描述性的,但我想不出更好的方式来描述它。

最终我想做的是:

我正在制作一个系统,通过 CSV 处理来自多家不同公司的数据导入。当然,每个公司的格式略有不同,每个列/标题中的数据量不同,排列也不同。

我可以:

  1. 将文件格式硬编码到程序中,编程快速且简单,但不抽象或面向未来

  2. 通过允许用户在系统中配置“文件格式”、拖放 CSV 标题并为每个传入文件格式保存预设来提供“动态性”。

我想做选项 2,但是我该怎么做呢?

我猜标签样式系统可以做到这一点......但任何建议将不胜感激。

我正在使用 PHP、MySQL 和 CodeIgniter 2.0.2(如果有帮助的话),并且还可以访问我的应用程序中的所有 Zend 库。

I know the title isn't the most descriptive, but I can't think of a better way to describe it.

Ultimately what I would like to do is this:

I am making a system that handles import of data via CSV from several different companies. Naturally, the format from each company is slightly different, with different amounts of data in each column/heading and a different arrangement.

I could either:

  1. Hard code the file format into the program, which is quick and simple to program, but not abstract or future proof

  2. or provide "dynamicity" by allowing users to configure "file formats" in the system, by dragging and dropping CSV headings and saving presets for each incoming file format.

I would like to do option 2, but how would I go about doing this?

I am guessing a tagging style system would do it... but any advice would be appreciated.

I am using PHP, MySQL, and CodeIgniter 2.0.2 if that helps, and also have access to all the Zend libraries in my app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

旧故 2024-11-09 22:33:04

假设用户将提交您预先定义的可能数据类型的子集,这应该不会太困难。

一个简单的表单允许用户选择数据类型并为您提供 csv 中的字段名称,可用于创建您提到的模板。将它们存储在与用户关联的数据库表中,并让他们在导入 csv 之前选择一个模板。对于拥有没有标题行的 csv 的客户,他们会告诉您每种数据类型的列号,略有不同。

我还建议为尚未定义导出的客户提供预定义格式。这样他们就可以将导出构建为您的一种格式。

您还可以让用户定义他们的默认模板。这样,如果他们始终以相同格式导入数据,则不必每次导入数据时都选择模板。

Assuming that users will be submitting a subset of possible data types that you define up front, this shouldn't be too tough.

A simple form that allows the user to select the data type and give you the field name in their csv could be used to create the templates you mentioned. Store these in a database table associated with the user and make them choose a template before importing a csv. For customers who have csvs without header rows, a slight variation where they tell you the column numbers for each data type.

I'd also suggest providing pre-defined formats for customers who haven't defined their exports yet. That way they could build their exports to one of your formats.

You could also let users define their default template. That way they wouldn't have to select the template every time they import data if they're always importing data in the same format.

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