将 CSV 响应附加到邮递员中现有的 excel
append CSV response to existing excel in postman
我发出了一个 GET 请求,得到了 text/csv 响应。但是,我想将其附加到已经存在的 excel 文件中。这可能吗?提前致谢。
#Generate your text
input_file = open("text/csv response")
input_text = input_file.read()
#Opening the excel file to append ("a")
f = open("your_file_name.csv","a")
#Write the iput text in the file that you want to be appended
f.write(input_text)
#close files otherwise you will get trouble opening them later.
f.close()
input_file.close()
除数据文件外,您不能直接在邮递员中使用外部文件。但是解决方法是使用可视化工具功能。在您的测试部分添加以下代码
//Assuming you have your csv content in the variable csv
csv = `pravz,1
test,2`
csv=JSON.stringify(csv)
a =`
<html>
<body>
<input type="file" id="fileinput" />
<pre id="ReadResult"></pre>
<script type="text/javascript">
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function (e) {
var contents = e.target.result;
contents = contents + "\n" + ${csv}
console.log(contents)
const blob = new Blob([contents], { type: 'text/plain' });
const a = document.createElement('a');
a.setAttribute('download', "fileName.csv");
a.setAttribute('href', window.URL.createObjectURL(blob));
a.click()
document.getElementsByTagName("body")[0].appendChild(a);
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
</script>
</body>
</html>`
pm.visualizer.set(a)
现在转到可视化选项卡:
只需上传您拥有的 csv 文件,这会将内容附加到该文件并询问保存文件的位置。
我发出了一个 GET 请求,得到了 text/csv 响应。但是,我想将其附加到已经存在的 excel 文件中。这可能吗?提前致谢。
#Generate your text
input_file = open("text/csv response")
input_text = input_file.read()
#Opening the excel file to append ("a")
f = open("your_file_name.csv","a")
#Write the iput text in the file that you want to be appended
f.write(input_text)
#close files otherwise you will get trouble opening them later.
f.close()
input_file.close()
除数据文件外,您不能直接在邮递员中使用外部文件。但是解决方法是使用可视化工具功能。在您的测试部分添加以下代码
//Assuming you have your csv content in the variable csv
csv = `pravz,1
test,2`
csv=JSON.stringify(csv)
a =`
<html>
<body>
<input type="file" id="fileinput" />
<pre id="ReadResult"></pre>
<script type="text/javascript">
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function (e) {
var contents = e.target.result;
contents = contents + "\n" + ${csv}
console.log(contents)
const blob = new Blob([contents], { type: 'text/plain' });
const a = document.createElement('a');
a.setAttribute('download', "fileName.csv");
a.setAttribute('href', window.URL.createObjectURL(blob));
a.click()
document.getElementsByTagName("body")[0].appendChild(a);
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
</script>
</body>
</html>`
pm.visualizer.set(a)
现在转到可视化选项卡:
只需上传您拥有的 csv 文件,这会将内容附加到该文件并询问保存文件的位置。