将 Excel 逗号分隔的单元格转换为包含 B 列值的行
Converting Excel comma separated cell into rows including B columns values
我们需要转换以下内容(实际有 218,000 行):
keyword businessId
here,are,keywords 459
more,keywords 460
进入下面这个例子:
keyword businessId
here 459
are 459
keywords 459
more 460
keywords 460
等等 218,000 行此数据。
我知道这最终会转变为大约 3,600,000 行,但我们需要这样做;无论是在一个脚本中还是在块中完成。帮忙?
Excel 可能会因尝试而失败,因为它有超过 100 万行的限制。因此,要么 sheet 需要拆分成更小的块,每个 sheet 一个,以防止这种情况发生,要么考虑用您选择的语言编写一个简短的脚本,以将输入流式传输到新的 csv 中。 C#'ey代码如下:
while(!eof)
{
string line = inFile.readline();
//assumes tab delimited between keyword/business id, but can be reworked for comma delimited
string[] lineParts = line.split('\t');
string[] keywords = lineParts.split(',');
int busId = Integer.Parseint(lineParts[1]);
for(string keyword : keywords)
{
outFile.writeLine(keyword + "," + busId);
}
}
或类似的东西 - 可能需要一些 try/catching 以防出现解析错误。
我们需要转换以下内容(实际有 218,000 行):
keyword businessId
here,are,keywords 459
more,keywords 460
进入下面这个例子:
keyword businessId
here 459
are 459
keywords 459
more 460
keywords 460
等等 218,000 行此数据。
我知道这最终会转变为大约 3,600,000 行,但我们需要这样做;无论是在一个脚本中还是在块中完成。帮忙?
Excel 可能会因尝试而失败,因为它有超过 100 万行的限制。因此,要么 sheet 需要拆分成更小的块,每个 sheet 一个,以防止这种情况发生,要么考虑用您选择的语言编写一个简短的脚本,以将输入流式传输到新的 csv 中。 C#'ey代码如下:
while(!eof)
{
string line = inFile.readline();
//assumes tab delimited between keyword/business id, but can be reworked for comma delimited
string[] lineParts = line.split('\t');
string[] keywords = lineParts.split(',');
int busId = Integer.Parseint(lineParts[1]);
for(string keyword : keywords)
{
outFile.writeLine(keyword + "," + busId);
}
}
或类似的东西 - 可能需要一些 try/catching 以防出现解析错误。