以下代码演示了 直接通过excel可以识别的文件结构生成xls文件的方法,这样就可以不引用麻烦的ole了xls生成软件手机版。 usingSystem; usingSystem。Collections。Generic; usingSystem。Text; namespaceConsoleApplication16 { classProgram { staticvoidMain(string[]args) { //不通过OLE生成excel文件的方法 ExcelWriterexcel=newExcelWriter(@"c:test。
xls"); excelxls生成软件手机版。BeginWrite(); excel。WriteString(0,0,"Name"); excel。WriteString(0,1,"Score"); excel。WriteString(1,0,"jinjazz"); excel。
WriteNumber(1,1,100); excelxls生成软件手机版。WriteString(2,0,"游客"); excel。WriteNumber(2,1,0); excel。EndWrite(); } } publicclassExcelWriter { System。
IOxls生成软件手机版。FileStream_wirter; publicExcelWriter(stringstrPath) { _wirter=newSystem。IO。FileStream(strPath,System。IO。FileMode。OpenOrCreate); } /// ///写入short数组 /// ///
privatevoid_writeFile(short[]values) { foreach(shortvinvalues) { byte[]b=Systemxls生成软件手机版。
BitConverterxls生成软件手机版。GetBytes(v); _wirter。Write(b,0,b。Length); } } /// ///写文件头 /// publicvoidBeginWrite() { _writeFile(newshort[]{0x809,8,0,0x10,0,0}); } /// ///写文件尾 /// publicvoidEndWrite() { _writeFile(newshort[]{0xa,0}); _wirter。
Close(); } /// ///写一个数字到单元格x,y /// ///
publicvoidWriteNumber(shortx,shorty,doublevalue) { _writeFile(newshort[]{0x203,14,x,y,0}); byte[]b=Systemxls生成软件手机版。
BitConverterxls生成软件手机版。GetBytes(value); _wirter。Write(b,0,b。Length); } /// ///写一个字符到单元格x,y /// ///
xls生成软件手机版。