所以现在我想出了如何写一个excel文件(非常感谢你们!),我想知道是否有办法写入excel中的第二列.我实际上是向这个excel文件发送了两个不同的变量,我希望它们并排放在一起,而不是彼此相邻.我没有看到任何其他问题要求C语言,所以我想把它扔出去.如果有的话,请随时链接我的问题,我为浪费空间而道歉!
File * fp;
fp = fopen("C:\\Documents and Settings\\MyName\\Desktop\\Filename.csv", "w");
if(fp == NULL){
printf("Couldn't open file\n");
return;
}
for (j = 0; j<Variable0; j++){
fprintf(fp, "%f\n", (j+Variable1);
fprintf(fp, "%f\n", (j+Variable2);
}
Run Code Online (Sandbox Code Playgroud)
您没有编写Excel文件,而是编写逗号分隔值文件(CSV).但是,它仍然可以用Excel打开.这是个很大的差异.每列用逗号分隔.每行由换行符分隔.
File * fp;
fp = fopen("C:\\Documents and Settings\\MyName\\Desktop\\Filename.csv", "w");
if(fp == NULL){
printf("Couldn't open file\n");
return;
}
float otherVar1 = 1.0f; // random thing you want to put in second column
float otherVar2 = 2.0f; // random thing you want to put in second column
for (j = 0; j<Variable0; j++){
fprintf(fp, "%f,%f\n", (j+Variable1), (otherVar1));
fprintf(fp, "%f,%f\n", (j+Variable2), (otherVar2));
}
Run Code Online (Sandbox Code Playgroud)
确保你还记得关闭文件!
fclose(fp);
Run Code Online (Sandbox Code Playgroud)