Экспорт в Excel в ColdFusion - PullRequest
0 голосов
/ 21 марта 2019

Я публикую несколько входных данных в URL с использованием cfhttp и ожидаю загрузки некоторых данных в файл xls.Я пытаюсь получить данные, используя cffile = "write", который не работает.Кто-нибудь может подсказать, как мы можем пойти с этим.Вот код ниже

<cfhttp url="#Baseurl#" method="post" result="ExportToExcelresult" redirect="no" resolveurl="true">
    <cfhttpparam type="header" name="REFERER" value="#Baseurl#" >
    <cfhttpparam type="header" name="Cache-Control" value="no-cache">
    <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
    <cfhttpparam type="header" name="Connection" value="keep-alive" >
    <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36">
    <cfhttpparam type="header" name="cookie" value="TestCookie=;" encoded="yes">

    <cfloop collection="#CookieList#" item="i">
            <cfhttpparam type="header" name="cookie" value="#CookieList[i]#" encoded="yes">
    </cfloop>
    <cfloop collection="#PostCookieList#" item="i">
            <cfhttpparam type="header" name="cookie" value="#PostCookieList[i]#" encoded="yes">
    </cfloop>

    <cfloop collection="#PostDefaultCookieList#" item="i">
            <cfhttpparam type="header" name="cookie" value="#PostDefaultCookieList[i]#" encoded="yes">
    </cfloop>


    <cfhttpparam name="ToolkitScriptManager1_HiddenField" value="" type="formfield">
    <cfhttpparam name="LeftNav1_LoginView1_treeView1_ExpandState" value="#EXPANDSTATE#" type="formfield">
    <cfhttpparam name="LeftNav1_LoginView1_treeView1_SelectedNode" value="#SELECTNODE#" type="formfield">
    <cfhttpparam name="__EVENTTARGET"  value="" type="formfield">
    <cfhttpparam name="__EVENTARGUMENT"  value="" type="formfield">
    <cfhttpparam name="LeftNav1_LoginView1_treeView1_PopulateLog" value="" type="formfield">
    <cfhttpparam name="__VIEWSTATE"  value="#VIEWSTATE#" type="formfield">
    <cfhttpparam name="__VIEWSTATEGENERATOR"  value="#VIEWSTATEGENERATOR#" type="formfield">
    <cfhttpparam name="__EVENTVALIDATION"  value="#EVENTVALIDATION#" type="formfield">
    <cfhttpparam name="ctl00$MainContent$repMUData$ctl00$btnExport"  value="Export to Excel" type="formfield">
</cfhttp>

Когда я делаю cfdump, вот результат

enter image description here

Когда я делаю cfdump, этодает некоторые двоичные данные.Конечно, я получаю некоторые данные, но не знаю, как извлечь данные в файл xls

1 Ответ

1 голос
/ 21 марта 2019

Для записи двоичных данных в файл просто используйте функцию filewrite. В следующем фрагменте я пишу во временный файл, но вы пишете туда, где хотите сохранить файл на постоянной основе. Затем я читаю файл обратно в объект электронной таблицы, чтобы убедиться, что запись работала как задумано.

<cfhttp url="http://example.com/test.cfm" result="ExportToExcelresult">
</cfhttp>
<cfscript>
    //Replace with the file path where you want to permanently store the file
    yourFileLocation = getTempFile(getTempDirectory() ,"xls");

    //Save to file system
    filewrite(yourFileLocation, ExportToExcelresult.filecontent.toByteArray());

    //Not needed. Only verifying there is a spreadsheet written to the file location
    writeOutput("Is spreadsheet: " & isSpreadsheetFile(yourFileLocation));

    //You will not be working with a temp file. Do not delete it.
    fileDelete(yourFileLocation);
</cfscript>
...