KDB:将 2 个或更多表保存到同一个 Excel/CSV 文件(添加 Header and/or 页脚)?
KDB: Save 2 or More Tables to the Same Excel/CSV File (Add Header and/or Footer)?
我有一个 table,我想导出到 Excel 或 CSV 文件。
供参考,table 称为 tradesFiltered
。
我正在使用 KDB 中的以下内容将 table 导出到 csv:
file:filePath,"CM_RBC_Trust_",string[first exec tradeDate from trades],".csv";
(`$file) 0: "," 0: tradesFiltered;
但现在我必须在 csv 文件中添加 header 和带有附加信息的页脚。例如,我需要在 Excel 中执行类似的操作,其中 header 中的附加信息是 hard-coded。
Cell A1 - MILVUS
Cell A3 - Date:
Cell A5 - To:
Cell A7 - From:
Cell B3 - MM/DD/YYYY
Cell B5 - <Name>
Cell B7 - Trade Support
Cell D7 - Phone Number:
Cell E7 - 604 123 4567
然后在单元格 A9 中,它是 table tradesFiltered
。
我该怎么做呢?
您始终可以使用稀疏 table 将其组合在一起,然后附加到 csv。不漂亮:
q)trades:([]sym:10?`3;px:10?100.0;sz:10?1000);
q)template:flip`MILVUS````!((`;`Date:;`;`To:;`;`From:);(`;`$"01/29/2019";`;`Name;`;`$"Trade Support");6#`;(5#`),`$"Phone Number";(5#`),`$"604 123 4567");
q)`:file.csv 0:","0:template;
q)h:hopen`:file.csv;
q)neg[h]"";
q)neg[h]","0:trades;
q)hclose h;
更简洁的方法可能是让 table 位于 header 的右侧而不是下方:
q)template:flip`MILVUS``Date:``To:``From:`!(4#"";4#"";("01/29/2018";"";"";"");4#"";("Name";"";"";"");4#"";("Trade Suport";"";"Phone Number:";"604 123 4567");4#"");
q)`:file.csv 0:","0:{@[x;til[c],#[;-1]count[y]-c:count x],'y}[template;trades];
我有一个 table,我想导出到 Excel 或 CSV 文件。
供参考,table 称为 tradesFiltered
。
我正在使用 KDB 中的以下内容将 table 导出到 csv:
file:filePath,"CM_RBC_Trust_",string[first exec tradeDate from trades],".csv";
(`$file) 0: "," 0: tradesFiltered;
但现在我必须在 csv 文件中添加 header 和带有附加信息的页脚。例如,我需要在 Excel 中执行类似的操作,其中 header 中的附加信息是 hard-coded。
Cell A1 - MILVUS
Cell A3 - Date:
Cell A5 - To:
Cell A7 - From:
Cell B3 - MM/DD/YYYY
Cell B5 - <Name>
Cell B7 - Trade Support
Cell D7 - Phone Number:
Cell E7 - 604 123 4567
然后在单元格 A9 中,它是 table tradesFiltered
。
我该怎么做呢?
您始终可以使用稀疏 table 将其组合在一起,然后附加到 csv。不漂亮:
q)trades:([]sym:10?`3;px:10?100.0;sz:10?1000);
q)template:flip`MILVUS````!((`;`Date:;`;`To:;`;`From:);(`;`$"01/29/2019";`;`Name;`;`$"Trade Support");6#`;(5#`),`$"Phone Number";(5#`),`$"604 123 4567");
q)`:file.csv 0:","0:template;
q)h:hopen`:file.csv;
q)neg[h]"";
q)neg[h]","0:trades;
q)hclose h;
更简洁的方法可能是让 table 位于 header 的右侧而不是下方:
q)template:flip`MILVUS``Date:``To:``From:`!(4#"";4#"";("01/29/2018";"";"";"");4#"";("Name";"";"";"");4#"";("Trade Suport";"";"Phone Number:";"604 123 4567");4#"");
q)`:file.csv 0:","0:{@[x;til[c],#[;-1]count[y]-c:count x],'y}[template;trades];