如何使用ColdFusion10將Excel電子表格上傳到現有表格中? 我有一個已保存的Excel電子表格,我有CFQuery(「myQuery」)輸出我需要的數據。如何循環查詢並導入到現有表中?如何使用coldfusion將Excel電子表格上傳到現有表格中?
數據庫:MS SQL服務器
至此,我明白,我需要遍歷查詢我有了所有的數據。
<cffunction name="uploadDogSheet" access="public" output="yes" returnType="void"
hint="upload the spreadSheet">
<cfset currentRowChecked = "1">
<cfset lastRow = numberOfRows> <!-- sets the number of rows that it will validate-->
<cfspreadsheet
action="read"
src="#SESSION.theExcelFile#"
headerrow= "1"
excludeHeaderRow = "true"
query = "allDoggyData"
rows = "1-#lastRow#" />
<cfscript>
allDataQuery = new Query(
sql ="SELECT * FROM allDoggyData",
dbtype = "query",
allData = allData);
allDataQueryResult = allDataQuery.execute().getResult();
</cfscript>
<cfloop query="allDoggyData">
<CFQUERY DATASOURCE="#mydatabase#" name="input_req">
insert into temp_dog_upload (dogNameColumn, dogBreedColumn, dogColor)
values
(
<cfqueryparam value="#allDoggyData.dogNameExcelColumn#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#allDoggyData.dogBreedExcelColumn#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#allDoggyData.dogColorExcelColumn#" cfsqltype="cf_sql_varchar">
)
</CFQUERY>
</cfloop>
<p>The sheet has been uploaded!<p></span>
你使用了什麼數據庫? MSSQL,MYSQL還是? – fyroc
數據庫:MS SQL Server – ConfusedDeer
爲什麼不直接在Management Studio中使用「導入數據」任務? – fyroc