Click here to Skip to main content
15,895,777 members
Home / Discussions / C#
   

C#

 
Questionscrols in grid column Pin
Nilish22-Jul-08 0:06
Nilish22-Jul-08 0:06 
AnswerRe: scrols in grid column Pin
stancrm22-Jul-08 1:53
stancrm22-Jul-08 1:53 
Questionweb site needs certificate Pin
George_George21-Jul-08 23:28
George_George21-Jul-08 23:28 
AnswerRe: web site needs certificate Pin
leppie22-Jul-08 5:29
leppie22-Jul-08 5:29 
GeneralRe: web site needs certificate Pin
George_George27-Jul-08 1:31
George_George27-Jul-08 1:31 
QuestionCreate Pop Server Pin
kathiresanmoorthy21-Jul-08 22:33
kathiresanmoorthy21-Jul-08 22:33 
GeneralRe: Create Pop Server Pin
Guffa21-Jul-08 23:41
Guffa21-Jul-08 23:41 
QuestionCreating different excel file and exporting datatbles in that Pin
Member 387988121-Jul-08 21:24
Member 387988121-Jul-08 21:24 
Hi i am having lot of tables in my dataset...,
Based on datatable first row first cell i am creating folder and creating excel file and export my datatble to that excel file...,

Everything is going on well...,

But during this perios lot of alert msg coming from excel side:
Do you want to save changes in "Book 61"
Like this upt o Book 73 or 73...,
Its coming on each folder creation time...,


This is my code:

for (int i = 0; i < DS.Tables.Count - 1; i++)
{
oXL = new Microsoft.Office.Interop.Excel.Application();
oWB = oXL.Workbooks.Add(System.Reflection.Missing.Value);
oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;
oRng = oSheet.Cells;
oSheet.Activate();
try
{
foreach (DataRow dr1 in DS.Tables[i].Rows)
{
foreach (DataRow dr2 in DS.Tables[i + 1].Rows)
{
if (dr1["MID"].ToString() == dr2["MID"].ToString())
{
DirectoryInfo dr = new DirectoryInfo("C:\\Test\\" + dr1["MID"].ToString() + @"\");
if (!dr.Exists)
{
dr.Create();
System.Data.DataTable dtToExport = DS.Tables[i];
GenerateExcelFile(ref dtToExport, oRng, 1);
FileInfo fi = new FileInfo("C:\\Test\\" + dr1["MID"].ToString() + "\\" + dr1["Name Of Employee"].ToString() + ".xls");
if (!fi.Exists)
{
oSheet.SaveAs("C:\\Test\\" + dr1["MID"].ToString() + "\\" + dr1["Name Of Employee"].ToString() + ".xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
oXL.Quit();
}
else
{
System.Data.DataTable dtToExport = DS.Tables[i + 1];
GenerateExcelFile(ref dtToExport, oRng, 1);
FileInfo fi = new FileInfo("C:\\Test\\" + dr2["MID"].ToString() + "\\" + dr2["Name Of Employee"].ToString() + ".xls");
if (!fi.Exists)
{
oSheet.SaveAs("C:\\Test\\" + dr2["MID"].ToString() + "\\" + dr2["Name Of Employee"].ToString() + ".xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
oXL.Quit();
}
}

else
{
DirectoryInfo dr = new DirectoryInfo("C:\\Test\\" + dr2["MID"].ToString() + @"\");
if (!dr.Exists)
{
dr.Create();
System.Data.DataTable dtToExport = DS.Tables[i + 1];
//oSheet.Activate();
GenerateExcelFile(ref dtToExport, oRng, 1);
FileInfo fi = new FileInfo("C:\\Test\\" + dr2["MID"].ToString() + "\\" + dr2["Name Of Employee"].ToString() + ".xls");

if (!fi.Exists)
{
oSheet.SaveAs("C:\\Test\\" + dr2["MID"].ToString() + "\\" + dr2["Name Of Employee"].ToString() + ".xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
oXL.Quit();
}
else
{
System.Data.DataTable dtToExport = DS.Tables[i];
GenerateExcelFile(ref dtToExport, oRng, 1);
FileInfo fi = new FileInfo("C:\\Test\\" + dr1["MID"].ToString() + "\\" + dr1["Name Of Employee"].ToString() + ".xls");
if (!fi.Exists)
{
oSheet.SaveAs("C:\\Test\\" + dr1["MID"].ToString() + "\\" + dr1["Name Of Employee"].ToString() + ".xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
oXL.Quit();
}
}
}
}
}
catch (Exception theException)
{
MessageBox.Show(theException.ToString(), "Error");
}
}

Plz guideme whats wrong in that?

Thanks & Regards,
NeW OnE,
please don't forget to vote on the post

AnswerRe: Creating different excel file and exporting datatbles in that Pin
Ashfield22-Jul-08 1:20
Ashfield22-Jul-08 1:20 
QuestionFocus in Dialog in Setup Project Pin
Sifar - 021-Jul-08 21:09
Sifar - 021-Jul-08 21:09 
QuestionUsing Unsafe code Pin
sumit703421-Jul-08 20:53
sumit703421-Jul-08 20:53 
AnswerRe: Using Unsafe code Pin
stancrm21-Jul-08 21:14
stancrm21-Jul-08 21:14 
GeneralRe: Using Unsafe code Pin
sumit703421-Jul-08 21:36
sumit703421-Jul-08 21:36 
QuestionBitmap to ByteArray Conversion...? Pin
DeepOceans21-Jul-08 19:59
DeepOceans21-Jul-08 19:59 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
stancrm21-Jul-08 21:16
stancrm21-Jul-08 21:16 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
Guffa21-Jul-08 23:50
Guffa21-Jul-08 23:50 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
Anthony Mushrow22-Jul-08 0:35
professionalAnthony Mushrow22-Jul-08 0:35 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
Lutosław22-Jul-08 0:40
Lutosław22-Jul-08 0:40 
Questionpop server connection Pin
kathiresanmoorthy21-Jul-08 19:35
kathiresanmoorthy21-Jul-08 19:35 
RantRe: pop server connection Pin
Guffa21-Jul-08 23:52
Guffa21-Jul-08 23:52 
Questionretreving the gridview row in color from sqlserver using boundfields Pin
santosh04221-Jul-08 18:53
santosh04221-Jul-08 18:53 
AnswerRe: retreving the gridview row in color from sqlserver using boundfields Pin
Srishti Mathur21-Jul-08 19:48
Srishti Mathur21-Jul-08 19:48 
Questionhow to get domain part from URL Pin
George_George21-Jul-08 17:22
George_George21-Jul-08 17:22 
AnswerRe: how to get domain part from URL Pin
Bert delaVega21-Jul-08 17:40
Bert delaVega21-Jul-08 17:40 
GeneralRe: how to get domain part from URL Pin
George_George21-Jul-08 18:14
George_George21-Jul-08 18:14 

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.