Click here to Skip to main content
15,917,174 members
Home / Discussions / C#
   

C#

 
QuestionDatabase Routines Pin
Wayne Phipps8-Feb-07 2:58
Wayne Phipps8-Feb-07 2:58 
AnswerRe: Database Routines Pin
Colin Angus Mackay8-Feb-07 3:33
Colin Angus Mackay8-Feb-07 3:33 
GeneralRe: Database Routines Pin
Wayne Phipps9-Feb-07 5:02
Wayne Phipps9-Feb-07 5:02 
QuestionExporting DataGrid to Excel Pin
pssuresh8-Feb-07 2:52
pssuresh8-Feb-07 2:52 
AnswerRe: Exporting DataGrid to Excel Pin
Sandeep Akhare8-Feb-07 3:11
Sandeep Akhare8-Feb-07 3:11 
GeneralRe: Exporting DataGrid to Excel Pin
pssuresh8-Feb-07 3:24
pssuresh8-Feb-07 3:24 
GeneralRe: Exporting DataGrid to Excel Pin
Sandeep Akhare8-Feb-07 3:44
Sandeep Akhare8-Feb-07 3:44 
GeneralRe: Exporting DataGrid to Excel [modified] Pin
pssuresh8-Feb-07 3:56
pssuresh8-Feb-07 3:56 
Hi,

use this link.i made my code from this link.

http://support.microsoft.com/kb/306023/EN-US/

and the following is my code


This is the windows application.when i truncate the data, it saves successfully, but when i increase the limit , then it throws the error.

// Start a new workbook in Excel.
excel = new Excel.Application();
books = (Excel.Workbooks)excel.Workbooks;
book = (Excel._Workbook)(books.Add(optionalValue));
sheets = (Excel.Sheets)book.Worksheets;
sheet = (Excel._Worksheet)(sheets.get_Item(1));
System.Data.DataView customizeGridView=(System.Data.DataView)CustomizeExportDataGrid.DataSource;
// Create an array for the headers and add it to cells A1:C1.
object[] headers=new object[customizeGridView.Table.Columns.Count];
//Read the column names from the view and add it as a column headers to excel sheet.
if(customizeGridView!=null)
{
for(int i=0;i < customizeGridView.Table.Columns.Count;i++)
{
headers[i]=customizeGridView.Table.Columns[i].ColumnName;
}
}


range = sheet.get_Range("A1", optionalValue);
if(customizeGridView.Table.Columns.Count > 0)
range = range.get_Resize(1,customizeGridView.Table.Columns.Count);
range.Value = headers;
range.EntireColumn.AutoFit();
font = range.Font;
font.Bold=true;
if(customizeGridView!=null)
{
// Create an array with 3 columns and 100 rowxs and add it to
// the worksheet starting at cell A2.
int rowcount=customizeGridView.Table.Rows.Count;
int ColumnCount=customizeGridView.Table.Columns.Count;
object[,] data = new Object[rowcount,ColumnCount];
int rowLoop=0;
int ColumnLoop=0;
//First the object values are copied and they are saved in to excel as a stretch to increase performance.
for(rowLoop=0;rowLoop <= rowcount-1;rowLoop++)
{
for(ColumnLoop=0;ColumnLoop <= ColumnCount-1;ColumnLoop++)
{
if(CustomizeExportDataGrid[rowLoop,ColumnLoop]==System.DBNull.Value)
data[rowLoop,ColumnLoop]=string.Empty;
else
{
data[rowLoop,ColumnLoop] = CustomizeExportDataGrid[rowLoop,ColumnLoop];
}
}
}
range = sheet.get_Range("A2", optionalValue);
range = range.get_Resize(rowcount,ColumnCount);
range.Value = data;
excel.DisplayAlerts=false;
book.SaveAs(filename, optionalValue, optionalValue,
optionalValue, optionalValue, optionalValue, Excel.XlSaveAsAccessMode.xlNoChange,
optionalValue, optionalValue, optionalValue, optionalValue);

Thanks,
Suresh.P.S


-- modified at 10:08 Thursday 8th February, 2007
QuestionBtrieve Database Pin
coolestCoder8-Feb-07 2:35
coolestCoder8-Feb-07 2:35 
QuestionCast to a Generic Type at runtime Pin
Florian Storck8-Feb-07 2:30
Florian Storck8-Feb-07 2:30 
QuestionDelegate Help Pin
JeremyLM8-Feb-07 2:29
JeremyLM8-Feb-07 2:29 
AnswerRe: Delegate Help Pin
aSarafian8-Feb-07 3:23
aSarafian8-Feb-07 3:23 
GeneralRe: Delegate Help Pin
JeremyLM8-Feb-07 4:04
JeremyLM8-Feb-07 4:04 
QuestionUpdating and removing nodes from a treeview Pin
sharpiesharpie8-Feb-07 2:12
sharpiesharpie8-Feb-07 2:12 
AnswerRe: Updating and removing nodes from a treeview Pin
Ravi Bhavnani8-Feb-07 6:16
professionalRavi Bhavnani8-Feb-07 6:16 
QuestionAdding compiled help to a C# project Pin
Antony M Kancidrowski8-Feb-07 1:58
Antony M Kancidrowski8-Feb-07 1:58 
AnswerRe: Adding compiled help to a C# project Pin
Sandeep Akhare8-Feb-07 3:14
Sandeep Akhare8-Feb-07 3:14 
GeneralRe: Adding compiled help to a C# project Pin
Antony M Kancidrowski8-Feb-07 4:24
Antony M Kancidrowski8-Feb-07 4:24 
Questionstring process Pin
Mohammad Daba'an8-Feb-07 1:56
Mohammad Daba'an8-Feb-07 1:56 
AnswerRe: string process Pin
Antony M Kancidrowski8-Feb-07 2:02
Antony M Kancidrowski8-Feb-07 2:02 
GeneralRe: string process Pin
Mohammad Daba'an8-Feb-07 2:06
Mohammad Daba'an8-Feb-07 2:06 
GeneralRe: string process Pin
Antony M Kancidrowski8-Feb-07 2:16
Antony M Kancidrowski8-Feb-07 2:16 
GeneralRe: string process Pin
Mohammad Daba'an8-Feb-07 2:23
Mohammad Daba'an8-Feb-07 2:23 
GeneralRe: string process Pin
aSarafian8-Feb-07 2:29
aSarafian8-Feb-07 2:29 
GeneralRe: string process Pin
Mohammad Daba'an9-Feb-07 20:36
Mohammad Daba'an9-Feb-07 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.