Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dot-Matrix Printer Resolution Problem Pin
Luc Pattyn17-May-11 0:57
sitebuilderLuc Pattyn17-May-11 0:57 
GeneralRe: Dot-Matrix Printer Resolution Problem Pin
ismail2017-May-11 1:00
ismail2017-May-11 1:00 
GeneralRe: Dot-Matrix Printer Resolution Problem Pin
Luc Pattyn17-May-11 1:05
sitebuilderLuc Pattyn17-May-11 1:05 
GeneralRe: Dot-Matrix Printer Resolution Problem Pin
ismail2017-May-11 1:11
ismail2017-May-11 1:11 
GeneralRe: Dot-Matrix Printer Resolution Problem Pin
ismail2017-May-11 1:29
ismail2017-May-11 1:29 
GeneralRe: Dot-Matrix Printer Resolution Problem Pin
ismail2017-May-11 2:08
ismail2017-May-11 2:08 
AnswerRe: Dot-Matrix Printer Resolution Problem Pin
Shameel17-May-11 4:15
professionalShameel17-May-11 4:15 
QuestionExport C# Windows Datagridview to excel Pin
sumit703416-May-11 19:09
sumit703416-May-11 19:09 
Hi I want to export Datagridview to excel. I have formatted my datagridview such that he negative values are shown as red, some values are bold and other formatting styles are applied. I want when I export it to Excel then it export with same formatted type.

Currently I Am using the below function to export. But unable to export with formatting.

private void exportAsExcel()
{
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
// creating new WorkBook within Excel application
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
// creating new Excelsheet in workbook
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
// see the excel sheet behind the program
//Funny
app.Visible = true;
// get the reference of first sheet. By default its name is Sheet1.
// store its reference to worksheet
try
{
//Fixed:(Microsoft.Office.Interop.Excel.Worksheet)
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets["Sheet1"];
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet;
// changing the name of active sheet
worksheet.Name = "Sheet1";
// storing header part in Excel
for (int i = 1; i < dgvDetails.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] = dgvDetails.Columns[i - 1].HeaderText;
}
worksheet.get_Range("A1", "AZ1").Font.Bold = true;
worksheet.get_Range("A1", "A" + (dgvDetails.RowCount + 2).ToString()).Font.Bold = true;
// storing Each row and column value to excel sheet
for (int i = 0; i < dgvDetails.Rows.Count; i++)
{
for (int j = 0; j < dgvDetails.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1] = dgvDetails.Rows[i].Cells[j].Value.ToString();
}
}

}
catch (System.Exception ex)
{

}
finally
{
app.Quit();
workbook = null;
app = null;
}
}
Thanks in advance
AnswerRe: Export C# Windows Datagridview to excel Pin
Ravi Sant16-May-11 23:13
Ravi Sant16-May-11 23:13 
AnswerRe: Export C# Windows Datagridview to excel Pin
ambarishtv17-May-11 0:37
ambarishtv17-May-11 0:37 
QuestionReading bookmarks in word Pin
Jia10016-May-11 18:54
Jia10016-May-11 18:54 
AnswerRe: Reading bookmarks in word Pin
Ravi Sant16-May-11 23:17
Ravi Sant16-May-11 23:17 
GeneralRe: Reading bookmarks in word Pin
Jia10017-May-11 0:19
Jia10017-May-11 0:19 
QuestionFlex UI .Net windows form in C# Pin
Thilina C16-May-11 17:36
Thilina C16-May-11 17:36 
AnswerRe: Flex UI .Net windows form in C# Pin
AspDotNetDev16-May-11 17:48
protectorAspDotNetDev16-May-11 17:48 
GeneralRe: Flex UI .Net windows form in C# Pin
Thilina C16-May-11 19:55
Thilina C16-May-11 19:55 
AnswerRe: Flex UI .Net windows form in C# Pin
BobJanova16-May-11 22:29
BobJanova16-May-11 22:29 
AnswerRe: Flex UI .Net windows form in C# Pin
0bx31-May-11 3:46
0bx31-May-11 3:46 
QuestionRealTime Pin
arkiboys16-May-11 9:27
arkiboys16-May-11 9:27 
AnswerRe: RealTime Pin
Ian Shlasko16-May-11 9:40
Ian Shlasko16-May-11 9:40 
GeneralRe: RealTime Pin
arkiboys16-May-11 9:58
arkiboys16-May-11 9:58 
GeneralRe: RealTime Pin
Keith Barrow16-May-11 10:25
professionalKeith Barrow16-May-11 10:25 
AnswerRe: RealTime [modified] Pin
dan!sh 16-May-11 10:28
professional dan!sh 16-May-11 10:28 
GeneralRe: RealTime Pin
Keith Barrow16-May-11 10:56
professionalKeith Barrow16-May-11 10:56 
GeneralRe: RealTime Pin
dan!sh 16-May-11 11:04
professional dan!sh 16-May-11 11:04 

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.