如何将一个byte[]写入Excel文件?
尽管我掌握了所有基础知识,但我对 C# 非常陌生。我本质上有一个用于加速度计 y 轴(上/下)的字节 [],我将其称为 Y[]。我需要一行代码将其导出到 Excel 文件(我使用 Office professional 2003)。我希望将值Y[0]写入单元格A1,Y[1]写入A2,依此类推(所以只有一列数据。这样做的目的是能够使用excel更轻松地操作数据并能够绘制它。我知道有像 zed graph 这样的 C# 绘图应用程序,但我更喜欢 excel,
我已经广泛查找,但没有找到任何可以帮助我的东西。文件,在上面写字,保存并关闭它。但是,如果您了解我的问题,请给我我需要的一两行代码,
谢谢 !很多人。
I am very new to c# although i control all the basics. I essentially have a byte [] for the y-axis of an accelerometer (up/down) which I called Y[]. I need one line of code to export this to an excel file (I work with Office professional 2003). I would like value Y[0] to be written to cell A1, Y[1] to A2, and so on ( so just one column of data. The purpose of this is to be able to use excel to manipulate the data more easily and be able to plot it. I know there are plotting apps for c# like zed graph but i preffer excel.
I have looked far and wide and havent found anything to help me. All i need to do is create an excel (.xls) file, write on it, save it and close it. But how? Do you use FileStream? or what? please if you understand my problem give me the one or two lines of code i need. I'm so close to finishing this little project!!!
Thanks a lot guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之后,通过以下方式将字节写入 Excel之前将其转换为字符串。可以在循环中完成 Y[] 数组的遍历。
上面链接中的代码片段
可以解锁您吗?
After that, write your byte into Excel by converting it to a String before. Going through your Y[] array can be done in a loop.
Code Snippet from link above
Does that unblock you?
所以,我最终使用的代码如下。
我有一个字节数组,我不会详细说明它是如何获得的,但它被称为 AllY []。然后我将其转换为一个名为 MyYData [] 的字符串数组,它保存相同的值,但采用字符串形式。
谢谢大家。我想说这个网站比“官方”微软 msdn 蹩脚网站好 100 倍。
此外,我忘记添加这一点,要使用 Excel 命令,您必须从项目菜单 > > 添加引用。添加参考> COM> Microsoft Excel 11.0 对象(数量可能有所不同)。然后在文档的标题处添加:
using Microsoft.Office.Core;
使用 Excel = Microsoft.Office.Interop.Excel;
大家欢呼吧,并保持编码!
So, the code I ended up using was the following.
I had a byte array which i'm not gonna go into details as to how it got it, but it was called AllY []. Then I transformed this into a string array called MyYData [] which held the same values but in string form.
Thank you everyone. And i'd like to say that this website works 100 times better than the "official" microsoft msdn crappy site.
Furthermore, i forgot to add that to use the excel commands you have to add a reference from the project menu > Add Reference > COM > Microsoft Excel 11.0 object (the number may vary). then at the header of the document, add:
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
Cheers everyone, and keep it coded!