Import Excel files to the database on the web page, export to the database

xiaoxiao2021-03-05  54

Due to work needs, in the OA system, the author needs to import the contents of the Excel file into the database, and you also need to export content in the database to the Excel file. The author's OA is developed with PHP and is applied to the web page, so it is relatively difficult to use PHP processing. After research, the author develops an ActiveX control with Delphi to process the data of the Excel file, then submit the data to the server, and save it into the database, easily implement the import of Excel file data. Export does not use the ActiveX control to process directly with PHP. The method is to generate the data directly to the CSV file because the CSV is a comma-separated text file, and can be opened directly with Excel, so the requirements can be met. The method of the implementation will be introduced below. Imported page code:

"People Number", "FieldName" => "stuffid", "FieldType" => "a"), array ("caption" => "start date", "FieldName" => "begindate", "FieldType" => "A"), array ("caption" => "end date", "FieldName" => "enddate", "FieldType" => "a"), array ("caption" => Contract content, "FieldName "=>" ContractText "," FieldType "=>" a "), array (" caption "=>" Note "," FieldName "=>" thisMemo "," FieldType "=>" A "), array (" Caption "=> Server File Name", "FieldName" => "DOCFILE", "FieldType" => "A"), array ("caption" => "file type", "fieldname" => "filetype", "FIELDTYPE" => "a"), array ("caption" => "FieldName" => "FileName", "FieldType" => "a"), array ("CAPTION" => " File extension, "fieldName" => "extname", "fieldType" => "a")))); // Construct SQL statement, field name part $ strsql = "INSERT INTO HR_WORKCONTRACT ("; $ str_ = "; For ($ I = 0; $ i <$ ncolnum - 1; $ i ) {$ strsql. = $ Arrtablestru [$ I] ["FieldName"]. ",";} $ strsql. = $ arrtablestrument NCOLNUM - 1] ["FieldName"]. ") Values"; $ strtmp = ""; // constructs SQL statement, data part for ($ I = 1; $ I <= $ nrownum; $ i ) {$ Strowchk = "rowchk". $ I; if ($$ strrowchk == "y") {$ strmp. = "("

For ($ J = 1; $ J ) {$ Strval = "Row". $ I. "col". $ j; if ($ Arrtablestru [$ j - 1] ["FieldType "] ==" a ") {$ strtmp. =" '"$$ strval.", ";} Else {$ strtmp. = $$ strval.", ";}} $ Strval =" row ". $ I. "col". $ ncolnum; if ($ Arrtablestru [$ ncolnum - 1] ["FieldType"] == "a") {$ strmp. = "'". $ STRVAL. "),"; } else {$ strtmp. = $ Strval. "),";} IF ($ IF ($ NBATNUM == 0) {$ 20 = Substr ($ 20, 0, Strlen ($ strt) - 2). " "; if (! $ do-> execsql ($ strsql. $ strup)) $ do-> setObject (" ERR "," Data Import Failed! "); Else $ Do-> SetObject (" ERR "," Data Import Success! "); // Echo $ strsql. $ Strtmp; $ strmp =" ";}}}}}}}} =" = "" {$ strmp = Substr ($ strmp, 0, strlen ($ strtmp, ) - 2). ";"; If (! $ Do-> execsql ($ strsql. $ Strmp)) $ do-> setObject ("ERR", "Data Import Failed!"); Else $ do-> setObject ( "Err", "Data Import Success!"); // Echo $ STRSQL. $ STRTMP;}}?>

Import of labor contract information Rel = "Stylesheet" Type = "text / css" href = "../../ common / formclass.css>