导出Excel表

using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Data.OleDb;
using  System.Windows.Forms;
using  System.Data;
using  Microsoft.Office.Interop.Excel;

namespace  BoyangMIS
{
   
    
class OutDataClass
    
{
        
//DataSet dst = new DataSet();
       
        
public Microsoft.Office.Interop.Excel.Application xlApp;
        Workbook wb;
        Worksheet ws;

        
public string modName;
        
public  DataSet dstExcel = new DataSet();
        
public OutDataClass(DataSet _dstExcel, string  _modName)
        
{
            
this.dstExcel = _dstExcel;
            
this.modName = _modName;
        }

        
//public int ModName
        
//{
        
//    get
        
//    {
        
//        return modName;
        
//    }
        
//    set
        
//    {
        
//        modName = value;
        
//    }
        
//}
        
//public DataSet Dstexcel
        
//{
        
//    get
        
//    {
        
//        return dstExcel;
        
//    }
        
//    set
        
//    {
        
//        dstExcel = value;
        
//    }
        
//}
        public  void OutDataExcel()
        
{
            
try
            
{
                xlApp 
= new Microsoft.Office.Interop.Excel.Application();
                wb 
= xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
               ws 
= (Worksheet)wb.Worksheets[1];

                
int iMaxRow = dstExcel.Tables[0].Rows.Count;
                
int iMaxCol = dstExcel.Tables[0].Columns.Count;
                
//设置公共格式
                ws.get_Range(ws.Cells[11], ws.Cells[1, iMaxCol]).Font.Name = "Tahoma";
                ws.get_Range(ws.Cells[
11], ws.Cells[1, iMaxCol]).Font.Bold = true;
                
//ws.get_Range(ws.Cells[1, 1], ws.Cells[1, iMaxCol]).Font.Size = 10;

                
                ws.get_Range(ws.Cells[
11], ws.Cells[iMaxRow + 1, iMaxCol]).Borders.LineStyle = 1;

                xlApp.Cells.Font.Size 
= 10;
                

                
//设置标题
                if (modName == "Room")
                    Room();
                
else if (modName == "RoomType")
                    RoomType();
                
else if (modName == "RoomSearch")
                    RoomSearch();
                
else if (modName == "RoomPrearrange")
                    RoomPrearrange();
                
else if (modName == "Reckoning")
                    Reckoning();
                
else if (modName == "ClientSearch")
                    ClientSearch();
                
else if (modName == "ClientInfo")
                    ClientInfo();

                
//填充数据
                for (int iRow = 0; iRow < iMaxRow; iRow++)
                
{
                    
for (int iCol = 0; iCol < iMaxCol; iCol++)
                    
{
                        xlApp.Cells[iRow 
+ 2, iCol + 1= dstExcel.Tables[0].Rows[iRow][iCol].ToString();
                    }

                }

                
//保存Execl
                
//xlApp.Save("C:/Room.xls");
                ////打开EXCEL
                xlApp.Visible = true;
            }

            
catch (Exception exp)
            
{
                MessageBox.Show(exp.ToString());
                
return;
            }


        }

        
private void Room()
        
{
            IniFile ini 
= new IniFile();
            ws.get_Range(ws.Cells[
11], ws.Cells[1,1]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomNumber"));
            ws.get_Range(ws.Cells[
12], ws.Cells[12]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomTypeName"));
            ws.get_Range(ws.Cells[
13], ws.Cells[13]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomFloor"));
            ws.get_Range(ws.Cells[
14], ws.Cells[14]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RatedCount"));
            ws.get_Range(ws.Cells[
15], ws.Cells[15]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RatedBed"));
            ws.get_Range(ws.Cells[
16], ws.Cells[16]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""ActuallyCount"));
            ws.get_Range(ws.Cells[
17], ws.Cells[17]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomState"));
            ws.get_Range(ws.Cells[
18], ws.Cells[18]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomMemo"));
                xlApp.Cells[
11= "房间号";
                xlApp.Cells[
12= "房间类型";
                xlApp.Cells[
13= "房间楼层";
                xlApp.Cells[
14= "额定人数";
                xlApp.Cells[
15= "额定床数";
                xlApp.Cells[
16= "实际人数";
                xlApp.Cells[
17= "房间状态";
                xlApp.Cells[
18= "备注";
        }

        
private void RoomType()
        
{
            IniFile ini 
= new IniFile();
            ws.get_Range(ws.Cells[
11], ws.Cells[11]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RoomTypeName"));
            ws.get_Range(ws.Cells[
12], ws.Cells[12]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RoomArea"));
            ws.get_Range(ws.Cells[
13], ws.Cells[13]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RatedBed"));
            ws.get_Range(ws.Cells[
14], ws.Cells[14]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RatedCount"));
            ws.get_Range(ws.Cells[
15], ws.Cells[15]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RoomPrice"));
            ws.get_Range(ws.Cells[
16], ws.Cells[16]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RoomTV"));
            ws.get_Range(ws.Cells[
17], ws.Cells[17]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RoomPhone"));
            ws.get_Range(ws.Cells[
18], ws.Cells[18]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RoomAir"));
            ws.get_Range(ws.Cells[
19], ws.Cells[19]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomTypeExcelColumn""RoomToilet"));
            xlApp.Cells[
11= "客房类型";
            xlApp.Cells[
12= "客房面积";
            xlApp.Cells[
13= "额定床数";
            xlApp.Cells[
14= "额定人数";
            xlApp.Cells[
15= "客房价格";
            xlApp.Cells[
16= "电视";
            xlApp.Cells[
17= "电话";
            xlApp.Cells[
18= "空调";
            xlApp.Cells[
19= "卫生间";
        }

        
private void RoomSearch()
        
{
            IniFile ini 
= new IniFile();
            ws.get_Range(ws.Cells[
11], ws.Cells[11]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomNumber"));
            ws.get_Range(ws.Cells[
12], ws.Cells[12]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomTypeName"));
            ws.get_Range(ws.Cells[
13], ws.Cells[13]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomFloor"));
            ws.get_Range(ws.Cells[
14], ws.Cells[14]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RatedCount"));
            ws.get_Range(ws.Cells[
15], ws.Cells[15]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RatedBed"));
            ws.get_Range(ws.Cells[
16], ws.Cells[16]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""ActuallyCount"));
            ws.get_Range(ws.Cells[
17], ws.Cells[17]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomMemo"));
            ws.get_Range(ws.Cells[
18], ws.Cells[18]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("RoomExcelColumn""RoomState"));
            xlApp.Cells[
11= "房间号";
            xlApp.Cells[
12= "房间类型";
            xlApp.Cells[
13= "房间楼层";
            xlApp.Cells[
14= "额定人数";
            xlApp.Cells[
15= "额定床位";
            xlApp.Cells[
16= "实际人数";
            xlApp.Cells[
17= "备注";
            xlApp.Cells[
18= "房间状态";
          
        }


        
private void RoomPrearrange()
        
{
            IniFile ini 
= new IniFile();
            ws.get_Range(ws.Cells[
11], ws.Cells[11]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientPrearrangeExC""ID"));
            ws.get_Range(ws.Cells[
12], ws.Cells[12]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientPrearrangeExC""ClientPName"));
            ws.get_Range(ws.Cells[
13], ws.Cells[13]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientPrearrangeExC""ClientPPhone"));
            ws.get_Range(ws.Cells[
14], ws.Cells[14]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientPrearrangeExC""ClientPRoom"));
            ws.get_Range(ws.Cells[
15], ws.Cells[15]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientPrearrangeExC""PrearrangeDate"));
            xlApp.Cells[
11= "序号";
            xlApp.Cells[
12= "预定者姓名";
            xlApp.Cells[
13= "预定电话";
            xlApp.Cells[
14= "预定房间";
            xlApp.Cells[
15= "预定时间";
        }

        
private void Reckoning()
        
{
            IniFile ini 
= new IniFile();
            ws.get_Range(ws.Cells[
11], ws.Cells[11]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""ID"));
            ws.get_Range(ws.Cells[
12], ws.Cells[12]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""ClientID"));
            ws.get_Range(ws.Cells[
13], ws.Cells[13]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""ClientName"));
            ws.get_Range(ws.Cells[
14], ws.Cells[14]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""RoomID"));
            ws.get_Range(ws.Cells[
15], ws.Cells[15]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""InDate"));
            ws.get_Range(ws.Cells[
16], ws.Cells[16]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""CheckDate"));
            ws.get_Range(ws.Cells[
17], ws.Cells[17]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""Settle"));
            ws.get_Range(ws.Cells[
18], ws.Cells[18]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientRecordExcelCloumn""ClientMemo"));
            xlApp.Cells[
11= "序号";
            xlApp.Cells[
12= "客户ID";
            xlApp.Cells[
13= "客户姓名";
            xlApp.Cells[
14= "房间";
            xlApp.Cells[
15= "入住日期";
            xlApp.Cells[
16= "退房日期";
            xlApp.Cells[
17= "结账金额";
            xlApp.Cells[
18= "备注";
            
        }

        
private void ClientSearch()
        
{
            Reckoning();
        }

        
private void ClientInfo()
        
{
            IniFile ini 
= new IniFile();
            ws.get_Range(ws.Cells[
11], ws.Cells[11]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientExcelColumn""ID"));
            ws.get_Range(ws.Cells[
12], ws.Cells[12]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientExcelColumn""ClientID"));
            ws.get_Range(ws.Cells[
13], ws.Cells[13]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientExcelColumn""ClientName"));
            ws.get_Range(ws.Cells[
14], ws.Cells[14]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientExcelColumn""ClientSex"));
            ws.get_Range(ws.Cells[
15], ws.Cells[15]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientExcelColumn""ClientAddress"));
            ws.get_Range(ws.Cells[
16], ws.Cells[16]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientExcelColumn""ClientPhone"));
            ws.get_Range(ws.Cells[
17], ws.Cells[17]).ColumnWidth = Convert.ToInt16(ini.IniReadValue("ClientExcelColumn""ClientMemo"));
            xlApp.Cells[
11= "序号";
            xlApp.Cells[
12= "客户ID";
            xlApp.Cells[
13= "客户姓名";
            xlApp.Cells[
14= "性别";
            xlApp.Cells[
15= "籍贯";
            xlApp.Cells[
16= "电话";
            xlApp.Cells[
17= "备注";
           
        }

    }

}

=======下面是parameter.ini文件内容===============

关于操作INI文件Class,请查看我的"简单操作INI文件"文章或联系我

[DataGridView]
pagesize = 10

[ControlPar]
Address = 北京,上海
Address1 = "北京"
Address2 = "上海"
Address3 = "天津"
Address4 = "重庆"


[RoomExcelColumn]
RoomNumber   = 5
RoomTypeName = 8
RoomFloor    = 7
RatedCount   = 7
RatedBed     = 7
ActuallyCount= 7
RoomState    = 7
RoomMemo     = 25


[RoomTypeExcelColumn]
RoomTypeName = 8
RoomArea     = 7
RatedBed     = 7
RatedCount   = 7
RoomPrice    = 7
RoomTV       = 7
RoomPhone    = 7
RoomAir      = 7
RoomToilet   = 7

[ClientRecordExcelCloumn]
ID           = 7
ClientID     = 20
ClientName   = 8
RoomID       = 7
InDate       = 15
CheckDate    = 15
Settle       = 7
ClientMemo   = 25

[ClientPrearrangeExC]
ID            = 7
ClientPName   = 8
ClientPPhone  = 10
ClientPRoom   = 7
PrearrangeDate= 15

[ClientExcelColumn]
ID           = 7
ClientID     = 20
ClientName   = 8
ClientSex    = 7
ClientAddress= 7
ClientPhone  = 10
ClientMemo   = 25

[Time]
;预定提示时间以分钟计算
Prearrange   = 30

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值