0

我有一棵具有响应单元结构的树。受访者所属单位。让我们假设银行有两个部门,所以我将拥有:

  + Accountants
     - Homer Simpson
     - Bart Simpson
     - Leny
  + It department 
     - Charles Bartowski
     - Sarah Walker
     - Bill

会计师和 IT 部门是部门,而受访者则是其中的一部分。每个respondent都有一般属性:

 - Email
 - Language
 - Name
 - DepartmentID

每个部门都可以为所有受访者提供自己的动态属性:

 - Salary
 - Respondent age
 - Gender

可以在运行时添加和删除此属性。它们存储为表

特性:

- Property name
- Property ID

属性值:

 - PropertyValueID
 - PropertyID
 - Value

我需要执行将它们导出到Excel文件中的可能性,然后用户可以在此 excel 中编辑 smth,当他将其上传到服务器时,应该更新数据库。

我确实在Excel中导出。现在我正在寻找执行允许上传的好方法。是否有任何文章或模式可以有效地做到这一点?

提前致谢)

我正在使用 ASP.NET 和 EPPlus 来处理 Excel。

4

1 回答 1

0

I will start my answer with a strong recommendation to not do this! =)

Exporting to Excel will be easy because your database is consistent and abides by certain rules and logic.

If you let a user modify an Excel file, let them upload it, and then try to parse it and update a database, you're asking for a lot of headaches.

Here is how you might think about doing it:

  1. First I would let them upload the file. Not sure what you're using for that, but it's the obvious start.
  2. Next I would create a job to import the Excel file into the database. If it's SQL Server, I would import it with an SSIS job as an example. The goal is to bring it in to your database in a temporary table.
  3. Write some code to read from the temporary table (which is your recently imported Excel data) and do validations. Validate the field names are correct, the data types are correct, etc.
  4. Write code to import the data from the temporary table to your master table(s). You only do this after you've verified programatically the imported file is good.
  5. Make sure you lock down Excel as much as possible. Lock the sheet(s) so the user can't modify your data entry template. Try to do validations in Excel so they don't use values that are wrong. (For example, if you have an enumeration, make sure they stick to it instead of putting in free form text.)

The real problem with this approach is that users are crazy and they will not follow your template or guidelines. I would expect to spend a lot of time debugging bad imports.

It's not an option to make a simple web application to let them add/edit data? That way you would have more control over their input. Excel potentially gives them too much power.

(Then again you can make forms with VBA in Excel to maybe restrict their input.)

于 2013-01-15T18:59:23.173 回答