Skip to content

Commit

Permalink
Merge pull request #22 from AamirWaseem/master
Browse files Browse the repository at this point in the history
Updates - Aspose .NET DNN Data Exporter to Excel using Aspose.Cells
  • Loading branch information
aspose-cells-gists committed Nov 6, 2015
2 parents 29bacff + 45c6a3e commit 1e1f98c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="Aspose.NET DNN Data Exporter to Excel" type="Module" version="00.00.01">
<friendlyName>Aspose .NET DNN Data Exporter to Excel using Apose.Cells</friendlyName>
<description>Aspose .NET DNN Data Exporter to Excel Module allows users to export ddata directly from local or remote database tables, views and by custom query into Microsoft Excel or OpenOffice Spreadsheet. This module demonstrates the powerful spreadsheet building feature provided by Aspose.Cells</description>
<package name="Aspose .NET Database Data Exporter for DNN to Excel" type="Module" version="00.00.01">
<friendlyName>Aspose .NET Database Data Exporter for DNN to Excel using Apose.Cells</friendlyName>
<description>Aspose .NET Database Data Exporter for DNN to Excel Module allows users to export data directly from local or remote database tables, views and by custom query into Microsoft Excel or OpenOffice Spreadsheet. This module demonstrates the powerful spreadsheet building feature provided by Aspose.Cells</description>
<iconFile>Images/aspose_logo.gif</iconFile>
<owner>
<name>Aspose.com</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<h3>Aspose.NET DNN Data Exporter to Excel Using Aspose.Cells</h3>
Aspose .NET DNN Data Exporter to Excel Module allows users to export data directly from local or remote database tables, views and by custom query into Microsoft Excel or OpenOffice Spreadsheet. This module demonstrates the powerful spreadsheet building feature provided by Aspose.Cells. This initial version of the module is enriched with the following cool features to make the Export process simple and easy to use
<h3>Aspose .NET Database Data Exporter for DNN to Excel Using Aspose.Cells</h3>
Aspose .NET DNN Database Data Exporter to Excel Module allows users to export data directly from local or remote database tables, views and by custom query into Microsoft Excel or OpenOffice Spreadsheet. This module demonstrates the powerful spreadsheet building feature provided by Aspose.Cells. This initial version of the module is enriched with the following cool features to make the Export process simple and easy to use
<ul>
<li>Allow to connect Local MS SQL Server Database</li>
<li>Allow to connect Remote MS SQL Server Database</li>
<li>Populate all Tables from connected database</li>
<li>Populate all Views from connected database</li>
<li>Allow to write Custom Query</li>
<li>Auto Fit Columns to contents length.</li>
<li>Allow to skip string more than 32k in excel cells (LoadOptions)</li>
<li>Apply Header Column formating as Bold Text</li>
<li>Allow to use as Data Source (Table, Views, Custom Query)</li>
<li>Export Data to Microsoft Excel Documents (.xls, .xlsx and .xlsb)</li>
<li>Export Data to Tab delimited text document (*.txt)</li>
Expand All @@ -19,6 +22,6 @@
<a href=http://www.aspose.com>Aspose</a> - Your File Format APIs<br />
<hr/>
<div class="License">
<h3>About Aspose .NET DNN Data Exporter to Excel using Aspose.Cells</h3>
<p>Aspose .NET DNN Data Exporter to Excel Module allows users to export ddata directly from local or remote database tables, views and by custom query into Microsoft Excel or OpenOffice Spreadsheet.</p>
<h3>About Aspose .NET Database Data Exporter for DNN to Excel using Aspose.Cells</h3>
<p>Aspose .NET Database Data Exporter for DNN to Excel Module allows users to export ddata directly from local or remote database tables, views and by custom query into Microsoft Excel or OpenOffice Spreadsheet.</p>
</div>
35 changes: 29 additions & 6 deletions Plugins/DNN/Aspose.DNN.DatabaseDataExporterToExcel/View.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected void ProcessButton_Click(object sender, EventArgs e)

String connString = txtConString.Text;
//**STRING UPDATED**
String Query = "SELECT * FROM " + ddlTables.SelectedValue;
String Query = "SELECT * FROM " + ddlTables.SelectedValue + " ORDER BY 1";
switch (ddlSource.SelectedValue)
{
case "0":
Expand All @@ -116,7 +116,7 @@ protected void ProcessButton_Click(object sender, EventArgs e)
error_msg.InnerHtml = "There are no tables to select data.";
return;
}
Query = "SELECT * FROM " + ddlTables.SelectedValue;
Query = "SELECT * FROM " + ddlTables.SelectedValue + " ORDER BY 1";
break;
case "1":
if (ddlViews.Items.Count <= 0)
Expand Down Expand Up @@ -144,14 +144,21 @@ protected void ProcessButton_Click(object sender, EventArgs e)

using (var cn = new SqlConnection(connString))
{
//opening database connection
cn.Open();

//creating datatable, sqlCommand and sqlReader objects
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(Query, cn);
SqlDataReader myReader = cmd.ExecuteReader();
dt.Load(myReader);

//Instantiate a new Workbook
Workbook book = new Workbook();
//creating leadoptions for excel file
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
loadOptions.CheckExcelRestriction = false;

//Instantiate a new Workbook with Load options to prevent max cell string length of 32k error
Workbook book = new Workbook(Server.MapPath("~/App_Data/Sample.xlsx"), loadOptions);

//Clear all the worksheets
book.Worksheets.Clear();
Expand All @@ -162,6 +169,15 @@ protected void ProcessButton_Click(object sender, EventArgs e)
//Data Table import to the worksheet, inserting from A1 cell of sheet
sheet.Cells.ImportDataTable(dt, true, "A1");

// Apply Hearder Row/First Row text to Bold
Cells.Style objStyle = new Cells.Style();
objStyle.Font.IsBold = true;

StyleFlag objStyleFlag = new StyleFlag();
objStyleFlag.FontBold = true;

sheet.Cells.ApplyRowStyle(0, objStyle, objStyleFlag);

// Fit columns width to contents
sheet.AutoFitColumns();

Expand Down Expand Up @@ -225,7 +241,7 @@ private void InitForm()
DataTable dt = new DataTable();
try
{
SqlCommand cmd = new SqlCommand("SELECT * FROM information_schema.tables", cn);
SqlCommand cmd = new SqlCommand("SELECT * FROM information_schema.tables ORDER BY TABLE_NAME", cn);
SqlDataReader myReader = cmd.ExecuteReader();
dt.Load(myReader);
ddlTables.DataSource = dt;
Expand All @@ -243,7 +259,7 @@ private void InitForm()

try
{
SqlCommand cmd = new SqlCommand("SELECT * FROM information_schema.views", cn);
SqlCommand cmd = new SqlCommand("SELECT * FROM information_schema.views ORDER BY TABLE_NAME", cn);
SqlDataReader myReader = cmd.ExecuteReader();
dt.Load(myReader);

Expand Down Expand Up @@ -277,6 +293,13 @@ private void InitForm()
txtCustomQuery.Style["display"] = "block";
break;
}

// Create sample Excel file to use while generating exported file
if (!File.Exists(Server.MapPath("~/App_Data/Sample.xlsx")))
{
File.Create(Server.MapPath("~/App_Data/Sample.xlsx"));
}

}

//Get Save File Formats
Expand Down

0 comments on commit 1e1f98c

Please sign in to comment.