using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
//写入Excel
public void WriteExcel(List<Point3d> oldPoints, List<Point3d> newPoints, string path)
{
try
{
//创建文件
StreamWriter sw = new StreamWriter(path, false, Encoding.GetEncoding("gb2312"));
StringBuilder sb = new StringBuilder();
long totalCount = oldPoints.Count();
//写入数据
sb.AppendFormat("序號,原座標X,原座標Y,原座標Z,現座標X,現座標Y,現座標Z\r\n");
for (int i = 0; i < totalCount; i++)
{
sb.AppendFormat("{0},{1},{2},{3},{4},{5},{6}\r\n", i.ToString(), oldPoints[i].X.ToString(),
oldPoints[i].Y.ToString(), oldPoints[i].Z.ToString(), newPoints[i].X.ToString(),
newPoints[i].Y.ToString(), newPoints[i].Z.ToString());
}
sw.Write(sb.ToString());
sw.Flush();
sw.Close();
}
catch (System.Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
C#写入大量数据到Excel
最新推荐文章于 2024-07-26 16:48:19 发布