In most projects, importing and exporting is an extremely common feature. In the previous blog post, has mentioned the dynamic export data, now we mainly talk about the import function, where the import is to read from the Excel file data source, before the official save to the database, you can preview the results, and can be edited and then saved to the database. In fact, there are not many things to say, mainly to achieve or a little complex, the following provides my method, the effect is as follows, if we have different methods, also hope to put forward.
1. First look at the imported table format. The table header here is not allowed to be modified. The data must start on the third line.
2. Select the imported file.
Upload.
3. Post-upload preview.
A careful friend would ask, why are there so few fields in the import field that show so many fields here? This is a series of information obtained from other tables, which makes it easy for users to understand information intuitively. The preview information here can be modified and saved. The changes will be marked with red. Such as.
Once saved, you can import the database.
When you view the database, the data matches.
And all of this is basically not necessary to change the code behind the background, just need to simply configure the XML file. The following is the code for XML.
<?XML version= "1.0" encoding= "Utf-8"?><EAIxmlns= "Urn:mapping-schema" from= "Excelfile" to= "Sqlserverdatabase"> <Source> <fileRange= "A2"DataSourceName= "Test.xls"name= "Sheet1"Titleline= "2"Autogencolumntitle= "false"Handtype= "EAI." Filehandler.excelexport "> </file> </Source> <Target> <Tablename= "Kal_usalrydtl"DataSourceName= "SQL Server"Handtype= "EAI." Databasehandler.sqlserverimport "> < Fields> <Fieldname= "Suser"Mapping= "Employee Number"PrimaryKey= "true"Cannull= "false"DbType= "Char"length= " the"Valock= "true"Nochange= "true"reftable= "Ltkpas_user"Valuefield= "USERID"Valuetitle= "Employee Number"Displayfield= "DESCRIPTION"DisplayTitle= "Name"> </Field> <Fieldname= "SALRY2"Mapping= "Wage Item Type"PrimaryKey= "true"Cannull= "false"DbType= "Char"length= "2"Valock= "true"Nochange= "true"></Field> <Fieldname= "DATE"Mapping= "Implementation Date"PrimaryKey= "true"Cannull= "false"DbType= "smalldatetime"Valock= "true"></Field> <Fieldname= "Salry"Mapping= "Wage item"PrimaryKey= "true"Cannull= "false"DbType= "char"length= "Ten"Nochange= "true"reftable= "KAL_SALRYTP1"Valuefield= "Salry"Valuetitle= "Wage item"Displayfield= "DESCR"DisplayTitle= "Payroll Item description"Reftoptablefield= "SALRYTP2"refptable= "KAL_SALRYTP2"Valuepfield= "SALRY2"Valueptitle= "Wage Item Type"Displaypfield= "DESCR"Displayptitle= "Wage Item type description" > </Field> <Fieldname= "QTY"Mapping= "Amount"Cannull= "false"DbType= "float" ></Field> <Fieldname= "CMT"Mapping= "Remarks"></Field> </ Fields> </Table> </Target></EAI>
View Code
Originally want to write something more, but is too busy, on the last, recently also less update blog, deliberately to gather the number. Let everyone know I still in it session bread where eat.
If you are interested in this function, you can join Q Group: (238916811) discuss together.
Preview and modification of imported materials