// ---------------------------------------------------------
// Rama Krishna's Export class
// Copyright (C) 2004 Rama Krishna. All rights reserved.
// ---------------------------------------------------------

# region Includes
using System;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Threading;

# endregion 
// Includes

namespace DMD.Web.Module
{
    # region Summary

    
/// <summary>
    
/// Exports datatable to CSV or Excel format.
    
/// This uses DataSet's XML features and XSLT for exporting.
    
/// </summary>
    
/// <example>
    
/// C#.Net Example to be used in WebForms
    
/// ------------------------------------- 
    
/// using MyLib.ExportData;
    
/// 
    
/// private void btnExport_Click(object sender, System.EventArgs e)
    
/// {
    
///   try
    
///   {
    
///     // Declarations
    
///     DataSet dsUsers =  ((DataSet) Session["dsUsers"]).Copy( );
    
///     MyLib.ExportData.Export oExport = new MyLib.ExportData.Export("Web"); 
    
///     string FileName = "UserList.csv";
    
///     int[] ColList = {2, 3, 4, 5, 6};
    
///     oExport.ExportDetails(dsUsers.Tables[0], ColList, Export.ExportFormat.CSV, FileName);
    
///   }
    
///   catch(Exception Ex)
    
///   {
    
///     lblError.Text = Ex.Message;
    
///   }
    
/// }    
    
///  
    
/// VB.Net Example to be used in WindowsForms
    
/// ----------------------------------------- 
    
/// Imports MyLib.ExportData
    
/// 
    
/// Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
/// 
    
///      Try    
    
///      
    
///     'Declarations
    
///     Dim dsUsers As DataSet = (CType(Session("dsUsers"), DataSet)).Copy()
    
///     Dim oExport As New MyLib.ExportData.Export("Win")
    
///     Dim FileName As String = "C:\\UserList.xls"
    
///     Dim ColList() As Integer = New Integer() {2, 3, 4, 5, 6}            
    
///     oExport.ExportDetails(dsUsers.Tables(0), ColList, Export.ExportFormat.CSV, FileName)     
    
///     
    
///   Catch Ex As Exception
    
///     lblError.Text = Ex.Message
    
///   End Try
    
///   
    
/// End Sub
    
/// </example>


    # endregion 
// Summary

    
public class Export
    
{        
        
public enum ExportFormat : int {CSV = 1, Excel = 2}// Export format enumeration
    
        System.Web.HttpResponse response;
        
private string appType;    
            
        
public Export()
        
{
            appType 
= "Web";
            response 
= System.Web.HttpContext.Current.Response;
        }


        
public Export(string ApplicationType)
        
{
            appType 
= ApplicationType;
            
if(appType != "Web" && appType != "Win"throw new Exception("Provide valid application format (Web/Win)");
            
if (appType == "Web") response = System.Web.HttpContext.Current.Response;
        }

        
        
ExportDetails OverLoad : Type#1 // ExportDetails OverLoad : Type#1

        
ExportDetails OverLoad : Type#2 // ExportDetails OverLoad : Type#2

        
ExportDetails OverLoad : Type#3 // ExportDetails OverLoad : Type#3

        
Export_with_XSLT_Web // Export_with_XSLT 

        
Export_with_XSLT_Windows // Export_with_XSLT 

        
CreateStylesheet // WriteStylesheet

    }


}

posted on 2005-12-27 17:17  RubyPDF  阅读(3472)  评论(1编辑  收藏  举报