写一个excel文件
2007-03-02 15:06
309 查看
//这是SmartExcelStructure.cs的代码
using System;
using System.Runtime.InteropServices;
namespace Genersoft.Platform.Application
{
/// <summary>
/// 读写EXCEL文件所需的所有结构体的定义
/// </summary>
///
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct FONT_RECORD
{
public short opcode;//49
public short length;//5+len(fontname)
public short FontHeight;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte FontAttributes1;//bit0 bold, bit1 italic, bit2 underline, bit3 strikeout, bit4-7 reserved
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte FontAttributes2;//reserved - always 0
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte FontNameLength;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct PASSWORD_RECORD
{
public short opcode;//47
public short length;//len(password)
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct HEADER_FOOTER_RECORD
{
public short opcode;//20 Header, 21 Footer
public short length;//1+len(text)
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte TextLength;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct PROTECT_SPREADSHEET_RECORD
{
public short opcode;//18
public short length;//2
public short Protect;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct FORMAT_COUNT_RECORD
{
public short opcode;//0x1f
public short length;//2
public short Count;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct FORMAT_RECORD
{
public short opcode;// 0x1e
public short length;//1+len(format)
[MarshalAs(UnmanagedType.U1, SizeConst=1)]public byte FormatLength;//len(format)
}//followed by the Format-Picture
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct COLWIDTH_RECORD
{
public short opcode;//36
public short length;//4
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte col1;//first column
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte col2;//last column
public short ColumnWidth;//at 1/256th of a character
}
// 'Beginning Of File record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct BEG_FILE_RECORD
{
public short opcode;
public short length;
public short version;
public short ftype;
}
// 'End Of File record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct END_FILE_RECORD
{
public short opcode;
public short length;
}
// 'true/false to print gridlines
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct PRINT_GRIDLINES_RECORD
{
public short opcode;
public short length;
public short PrintFlag;
}
// 'Integer record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct tInteger
{
public short opcode;
public short length;
public short row;//unsigned integer
public short col;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;//rgbAttr1 handles whether cell is hidden and/or locked
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;//rgbAttr2 handles the Font# and Formatting assigned to this cell
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;//rgbAttr3 handles the Cell Alignment/borders/shading
public short intValue;//the actual integer value
}
// 'Number record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct tNumber
{
public short opcode;
public short length;
public short row;
public short col;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;
public double NumberValue;//8 Bytes
}
//
// 'Label (Text) record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct tText
{
public short opcode;
public short length;
public short row;
public short col;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte TextLength;
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct MARGIN_RECORD_LAYOUT
{
public short opcode;
public short length;
public double MarginValue;//8 bytes
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct HPAGE_BREAK_RECORD
{
public short opcode;
public short length;
public short NumPageBreaks;
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct DEF_ROWHEIGHT_RECORD
{
public int opcode;
public int length;
public int RowHeight;
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct ROW_HEIGHT_RECORD
{
public int opcode;//08
public int length;//should always be 16 bytes
public int RowNumber;
public int FirstColumn;
public int LastColumn;
public int RowHeight;//written to file as 1/20ths of a point
public int internals;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte DefaultAttributes;//set to zero for no default attributes
public int FileOffset;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;
}
}
using System;
using System.Runtime.InteropServices;
namespace Genersoft.Platform.Application
{
/// <summary>
/// 读写EXCEL文件所需的所有结构体的定义
/// </summary>
///
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct FONT_RECORD
{
public short opcode;//49
public short length;//5+len(fontname)
public short FontHeight;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte FontAttributes1;//bit0 bold, bit1 italic, bit2 underline, bit3 strikeout, bit4-7 reserved
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte FontAttributes2;//reserved - always 0
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte FontNameLength;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct PASSWORD_RECORD
{
public short opcode;//47
public short length;//len(password)
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct HEADER_FOOTER_RECORD
{
public short opcode;//20 Header, 21 Footer
public short length;//1+len(text)
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte TextLength;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct PROTECT_SPREADSHEET_RECORD
{
public short opcode;//18
public short length;//2
public short Protect;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct FORMAT_COUNT_RECORD
{
public short opcode;//0x1f
public short length;//2
public short Count;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct FORMAT_RECORD
{
public short opcode;// 0x1e
public short length;//1+len(format)
[MarshalAs(UnmanagedType.U1, SizeConst=1)]public byte FormatLength;//len(format)
}//followed by the Format-Picture
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct COLWIDTH_RECORD
{
public short opcode;//36
public short length;//4
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte col1;//first column
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte col2;//last column
public short ColumnWidth;//at 1/256th of a character
}
// 'Beginning Of File record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct BEG_FILE_RECORD
{
public short opcode;
public short length;
public short version;
public short ftype;
}
// 'End Of File record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct END_FILE_RECORD
{
public short opcode;
public short length;
}
// 'true/false to print gridlines
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct PRINT_GRIDLINES_RECORD
{
public short opcode;
public short length;
public short PrintFlag;
}
// 'Integer record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct tInteger
{
public short opcode;
public short length;
public short row;//unsigned integer
public short col;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;//rgbAttr1 handles whether cell is hidden and/or locked
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;//rgbAttr2 handles the Font# and Formatting assigned to this cell
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;//rgbAttr3 handles the Cell Alignment/borders/shading
public short intValue;//the actual integer value
}
// 'Number record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct tNumber
{
public short opcode;
public short length;
public short row;
public short col;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;
public double NumberValue;//8 Bytes
}
//
// 'Label (Text) record
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct tText
{
public short opcode;
public short length;
public short row;
public short col;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte TextLength;
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct MARGIN_RECORD_LAYOUT
{
public short opcode;
public short length;
public double MarginValue;//8 bytes
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct HPAGE_BREAK_RECORD
{
public short opcode;
public short length;
public short NumPageBreaks;
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct DEF_ROWHEIGHT_RECORD
{
public int opcode;
public int length;
public int RowHeight;
}
//
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
struct ROW_HEIGHT_RECORD
{
public int opcode;//08
public int length;//should always be 16 bytes
public int RowNumber;
public int FirstColumn;
public int LastColumn;
public int RowHeight;//written to file as 1/20ths of a point
public int internals;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte DefaultAttributes;//set to zero for no default attributes
public int FileOffset;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr1;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr2;
[MarshalAs(UnmanagedType.I1, SizeConst=1)]public byte rgbAttr3;
}
}
相关文章推荐
- 一个的Excel文件操作类--ExcelHelper
- 导出多个sheet的Excel以及在服务器上压缩文件然后再导出(在这里是压缩一个excel后导出)
- 一个简单的excel文件上传到数据库方法
- C#读写EXCEL源码提示“office检测到此文件存在一个问题。为帮助保护您的计算机,不能打开此文件。 ”的解决
- C#技巧【调用线程无法访问此对象,因为另一个线程拥有该对象的问题的解决办法】【C#读写EXCEL源码提示“office检测到此文件存在一个问题。为帮助保护您的计算机,不能打开此文件”的解决】
- 把一个 Excel 文件中的内容读到内表中的函数
- 64位word2013、Excel 2013、提示内存不足,PowerPoint 2013无法打开文件的一个解决方案
- python读写excel(附上将一个文件夹下所有excel文件合并成一个文件的代码)
- 用groovy简化java反射编写一个基于行数据对象的自动生成excel文件对象的工具
- C#利用NPOI在同一个Excel文件中创建多个sheet
- 发布一个biztalk 解析Excel文件到xml消息的管道组件
- Office 2003 VBA 遍历目录下的Excel批量拷贝Sheet 组成一个大的Excel文件
- vbs宏:excel读取多个文件并合并为一个文件
- c# .Net :Excel NPOI导入导出操作教程之List集合的数据写到一个Excel文件并导出
- 将多个word数据文件整理为一个excel文件
- Win7、Windows Server 2008下无法在Windows Service中打开一个已经存在的Excel 2007文件问题的解决方案
- 多个Excel文件的第一个工作表(Sheet)合并到一个Excel文件的多个工作表里
- “找不到文件或程序集名称“Interop.Microsoft.Office.Interop.Excel”,或找不到它的一个依赖项”的一种原因
- EXCEL:为一个EXCEL文件创建多个工作表
- c#(Asp.net)多个Excel文件合并到一个新的excel中