[M1 Mac, Big Sur 11.6.5, no Xcode]
PythonのライブラリNumPyでリストをcsvファイル化できるようにしました。
様々な方法がありますが、入れ子になったリストに対応できるNumPyを選択しました。
コードは以下の通りです。
<該当箇所のみ>
#include <Cocoa/Cocoa.h>
#include "process.h"
NSString* result;
NSString* path;
NSString* list;
Convert* convert;
- (IBAction) OnButton1Click:(id)sender {
onoff_XlsxToList = radioButton_a1.state;
onoff_XlsxToCsv = radioButton_a2.state;
onoff_ListToXlsx = radioButton_b1.state;
onoff_ListToCsv = radioButton_b2.state;
onoff_CsvToXlsx = radioButton_c1.state;
onoff_CsvToList = radioButton_c2.state;
if (radioButton_a1.state == 1){
rbtn_num = 1;
} else if (radioButton_a2.state == 1){
rbtn_num = 2;
} else if (radioButton_b1.state == 1){
rbtn_num = 3;
} else if (radioButton_b2.state == 1){
rbtn_num = 4;
} else if (radioButton_c1.state == 1){
rbtn_num = 5;
} else {
rbtn_num = 6;
}
NSLog(@"%d",rbtn_num);
switch (rbtn_num){
case 1:
case 2:
case 5:
case 6:
path = [textBox1 stringValue];
convert = [[Convert alloc] init];
result = [convert ConvertFunc:path number:rbtn_num];
[textview setString:result];
break;
case 3:
case 4:
list = [textBox2 stringValue];
convert = [[Convert alloc] init];
result = [convert ConvertFunc:list number:rbtn_num];
[textview setString:result];
break;
}
}
<該当箇所のみ>
import numpy as np
def list_to_csv(list):
home = os.path.expanduser('~')
file = home + '/Desktop/ltoc.csv'
new_list = eval(list)
np.savetxt(file, new_list, delimiter =",",fmt ='% s')
return "list_to_csv success"