Excel 插件数据验证

发布于 2025-01-03 07:03:33 字数 530 浏览 0 评论 0原文

我正在努力说服自己哪个想法更好。任何建议都会有帮助。故事是这样的:

我有一个 Excel 工作表,其中充满了项目,每一行代表一个项目。我需要验证数据以检查有效性。当且仅当该项目的每个数据元素也有效时,该项目才是有效的。还有一些人在做一个项目。可以有很多人从事一个项目(假设一个人只能从事一个项目)。因此,对于每个人,我需要验证它是一组字段,并确保它引用的项目确实存在。一切都经过验证后,我会将项目和人员推送到数据库。

另一件需要考虑的事情是,可能有数千个项目。凭借这种美德,还可以有更多数千人。

我想到了两种验证技术:

  1. 让项目和人员对象负责自己的数据验证。这意味着我必须在验证时创建对象,然后在全部验证后推送它们。我认为将这么多对象存储在内存中进行验证然后稍后推送是不可行的。
  2. 使用单独的函数来验证数据。该函数只会查看数据,确定其类型,并确保其满足约束 - 无论它是否属于个人或项目。这避免了创建项目和人员对象,但这也意味着我必须再次传递数据来创建这些对象。这也意味着,如果我向项目添加另一个字段,我必须向验证器函数添加另一个相应的部分。

I am struggling to convince myself which idea is better. Any advice would be helpful. Here is the story:

I have an excel sheet, full of projects with each row representing a project. I need to validate the data to check for validity. A project is valid if and only if every data element of that project is valid too. There are also people who work on a project. There can be many people who work on the one project (assume that a person can only work on one project). So for each person, i need to valid it's one set of fields, and make sure that the project it references does in fact exist. After everything is validated, i will then push projects and people to a database.

Another thing to consider, there can be many thousands of projects. By that virtue, there can also be many more thousands of people.

I have two validation techniques in mind:

  1. Make the projects and people objects responsible for their own data validation. This means i would have to create the objects at validation time, and then push them after they are all validated. I dont think it's feasible to store this many objects in memory to validate and then push later.
  2. Use a separate function to validate data. The function would only look at the data, determine its type, and makes sure it meets constraints - regardless if it belongs to a person or project. This avoids created project and people objects, but then it also means i have to make another pass over the data to create those objects. It also means that if i add another field to a project, I have to go add another corresponding piece to the validator function.

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

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

发布评论

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

评论(1

自我难过 2025-01-10 07:03:33

绝对是第一。创建几千个对象就可以了。您可能有超过一千兆的内存可供使用,这相当多了:)只要让您的对象尽可能小就可以了。

如果是我,我什至不会费心将其编写为 VSTO excel 加载项 - 我会编写一个单独的 ASP.NET 网页,他们可以在其中上传他们的 excel 文件。从那里您可以解析它,验证它并将其插入到您的数据库中。只是吐出一条“单元格 X 失败,因为 Y 丢失”消息。如果您将其编写为加载项,那么您需要有人将其安装在所有用户计算机上,并且任何错误修复都需要推出和更新,这将是 PITA。如果您确实需要进行一些巧妙的 Excel 交互,我只会采用 VSTO 路线。

Definitely number 1. Creating a few thousand objects will be fine. You've probably got over a gig of memory to work with, that's quite a lot :) Just keep your objects as small as possible and it'll be ok.

If it was me I wouldn't even bother writing it as a VSTO excel add-in - I'd write a separate ASP.NET web page where they could upload their excel file. From there you can parse it, validate it and insert it into your DB. Just spit out a "Failed on cell X because Y is missing" message. If you write it as an add-in then you'll need to someone get it installed on all of the users machines, and any bug fixes will need to be pushed out and updated, which will be a PITA. I'd only go down the VSTO route if you really need to do some clever excel interaction.

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