javascript - 如何在 Excel 单元格中插入换行符
问题描述
我必须解析从 Zephyr 为 Jira 导出的测试用例的 csv 文件。我需要以一种可以将它们导入新的测试管理系统的方式对它们进行格式化。新格式要求测试步骤位于一个由换行符分隔的单元格中,如下所示:
这是我编写的用于解析的脚本。步骤和预期结果都添加到同一个单元格中,但没有换行符。
const fs = require("fs");
const Papa = require("papaparse");
// ******************* user defined values ******************* //
// file to parse
const file = process.argv[2];
// ******************* parse csv ******************* //
const parsedTests = [];
// create file object
const fileObject = fs.readFileSync(file, "utf8");
// set config
const config = {
header: true,
complete: function(results) {
return results;
}
};
// parse and save results
const results = Papa.parse(fileObject, config);
const arr = Object.values(results.data);
function addTests(parsedTests, test) {
const found = parsedTests.some(el => el.ExecutionId === test.ExecutionId);
if (!found) {
parsedTests.push(test);
}
return parsedTests;
}
function addSteps(parstedTests, test, el) {
const found = parsedTests.some(el => el.ExecutionId === test.ExecutionId);
if (found && test.OrderId > 1) {
test.Step += `${test.Step}\n\n`;
test.ExpectedResults += `${test.ExpectedResults}\n\n`;
}
}
arr.forEach(el => {
addTests(parsedTests, el);
});
arr.forEach(el => {
addSteps(parsedTests, el);
});
console.log(parsedTests)
// write back to csv
fs.writeFileSync("./parsedtests.csv", Papa.unparse(parsedTests));
解决方案
推荐阅读
- jupyter-notebook - 无法同情以减少差异表达
- sage - 绘制一个使用数组的 python 函数
- django - 在 django 中计算并保存发票总额
- postgresql - 如何使用 Kotlin 的 Ktorm 对自定义 Postgres“对象类型”执行 WHERE 子句操作,避免“PSQLException:错误:运算符不存在”
- docker - Docker Compose Mac 错误:无法启动服务 zoo1:安装被拒绝:
- reporting-services - SSRS 表达式在 rdl 中除以零
- veins - sumo-launchd.py 相扑检查
- google-api - 有没有办法在 Google Drive API 上列出文件的所有字段?
- asp.net - 为什么我的图片在以前工作的网站中消失了 (404)?
- jquery - 嗨,我正在使用 BuddyX 主题和 buddyboss 平台插件。问题是,它没有在活动或群组中的帖子上显示“喜欢”的数量