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

C#

 
AnswerRe: Populating Data from MS Access Pin
Eddy Vluggen3-Mar-09 8:09
professionalEddy Vluggen3-Mar-09 8:09 
AnswerRe: Populating Data from MS Access Pin
haroon19803-Mar-09 11:38
haroon19803-Mar-09 11:38 
QuestionWriting SQL statement in C# Pin
Deepali Khalkar3-Mar-09 6:39
Deepali Khalkar3-Mar-09 6:39 
AnswerRe: Writing SQL statement in C# Pin
Yusuf3-Mar-09 8:32
Yusuf3-Mar-09 8:32 
QuestionCannot use Java generated DES Key in C# Pin
karpolu3-Mar-09 6:13
karpolu3-Mar-09 6:13 
AnswerRe: Cannot use Java generated DES Key in C# Pin
Calin Tatar3-Mar-09 10:02
Calin Tatar3-Mar-09 10:02 
AnswerRe: Cannot use Java generated DES Key in C# Pin
karpolu3-Mar-09 11:33
karpolu3-Mar-09 11:33 
QuestionDefault oreintation landscape ,datetime and Tabname in the footer when user print the excel sheet by default. Pin
vikram_asv3-Mar-09 5:59
vikram_asv3-Mar-09 5:59 
Hello all,
Could anyone tell me how to setup orientation to landscape, and datetime , and tabname in footer when user print the excel sheet by default. i am sending my excel code.Could any one tell what i need to do i search in google but no luck I need In C#.

public static void excelprint(DataSet source, string fileName)
{
bool status = false;
try
{
System.IO.StreamWriter excelDoc;
excelDoc = new System.IO.StreamWriter(fileName);
const string startExcelXML = "<xml version>\r\n<Workbook " +
"xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" +
" xmlnsBlush | :O =\"urn:schemas-microsoft-com:office:office\"\r\n " +
"xmlns:x=\"urn:schemas- microsoft-com:office:" +
"excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:" +
"office:spreadsheet\">\r\n <Styles>\r\n " +
"<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " +
"<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" +
"\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" +
"\r\n <Protection/>\r\n </Style>\r\n " +
"<Style ss:ID=\"BoldColumn\">\r\n <Font " +
"x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n " +
"<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat" +
" ss:Format=\"@\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"Decimal\">\r\n <NumberFormat " +
"ss:Format=\"0.00\"/>\r\n </Style>\r\n " +
"<Style ss:ID=\"Integer\">\r\n <NumberFormat " +
"ss:Format=\"0\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"DateLiteral\">\r\n <NumberFormat " +
"ss:Format=\"mm/dd/yyyy;@\"/>\r\n </Style>\r\n " +
"</Styles>\r\n ";
const string endExcelXML = "</Workbook>";
int rowCount = 0;
int sheetCount = 1;

excelDoc.Write(startExcelXML);

for (int worksheet = 0; worksheet < source.Tables.Count; worksheet++)
{


excelDoc.Write("<Worksheet ss:Name=\"" + source.Tables[worksheet].TableName + "\">");
excelDoc.Write("<Table>");
excelDoc.Write("<Row>");


for (int x = 0; x < source.Tables[worksheet].Columns.Count; x++)
{
excelDoc.Write("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">");
excelDoc.Write(source.Tables[worksheet].Columns[x].ColumnName);
excelDoc.Write("</Data></Cell>");
}
excelDoc.Write("</Row>");

for (int x = 0; x < source.Tables[worksheet].DefaultView.Count; x++)
{
rowCount++;
if (rowCount == 64000)
{
rowCount = 0;
sheetCount++;
excelDoc.Write("</Table>");
excelDoc.Write(" </Worksheet>");
excelDoc.Write("<Worksheet ss:Name=\"Sheet" + worksheet + "\">");
excelDoc.Write("<Table>");
}
excelDoc.Write("<Row>"); //ID=" + rowCount + "
for (int y = 0; y < source.Tables[worksheet].Columns.Count; y++)
{
System.Type rowType;
rowType = source.Tables[worksheet].DefaultView[x][y].GetType();
switch (rowType.ToString())
{
case "System.String":
//string XMLstring = x[y].ToString();
string XMLstring = source.Tables[worksheet].DefaultView[x][y].ToString();
XMLstring = XMLstring.Trim();
XMLstring = XMLstring.Replace("&", "&");
XMLstring = XMLstring.Replace(">", ">");
XMLstring = XMLstring.Replace("<", "<");
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
excelDoc.Write(XMLstring);
excelDoc.Write("</Data></Cell>");
break;
case "System.DateTime":
// DateTime XMLDate = (DateTime)x[y];
DateTime XMLDate = (DateTime)source.Tables[worksheet].DefaultView[x][y];
string XMLDatetoString = "";
XMLDatetoString = XMLDate.Year.ToString() +
"-" +
(XMLDate.Month < 10 ? "0" +
XMLDate.Month.ToString() : XMLDate.Month.ToString()) +
"-" +
(XMLDate.Day < 10 ? "0" +
XMLDate.Day.ToString() : XMLDate.Day.ToString()) +
"T" +
(XMLDate.Hour < 10 ? "0" +
XMLDate.Hour.ToString() : XMLDate.Hour.ToString()) +
":" +
(XMLDate.Minute < 10 ? "0" +
XMLDate.Minute.ToString() : XMLDate.Minute.ToString()) +
":" +
(XMLDate.Second < 10 ? "0" +
XMLDate.Second.ToString() : XMLDate.Second.ToString()) +
".000";
excelDoc.Write("<Cell ss:StyleID=\"DateLiteral\">" +
"<Data ss:Type=\"DateTime\">");
excelDoc.Write(XMLDatetoString);
excelDoc.Write("</Data></Cell>");

break;
case "System.Boolean":
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
//excelDoc.Write(x[y].ToString());
excelDoc.Write(source.Tables[worksheet].DefaultView[x][y].ToString());
excelDoc.Write("</Data></Cell>");
break;
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.Byte":
excelDoc.Write("<Cell ss:StyleID=\"Integer\">" +
"<Data ss:Type=\"Number\">");
// excelDoc.Write(x[y].ToString());
excelDoc.Write(source.Tables[worksheet].DefaultView[x][y].ToString());
excelDoc.Write("</Data></Cell>");
break;
case "System.Decimal":
case "System.Double":
excelDoc.Write("<Cell ss:StyleID=\"Decimal\">" +
"<Data ss:Type=\"Number\">");
// excelDoc.Write(x[y].ToString());
excelDoc.Write(source.Tables[worksheet].DefaultView[x][y].ToString());
excelDoc.Write("</Data></Cell>");
break;
case "System.DBNull":
excelDoc.Write("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
excelDoc.Write("");
excelDoc.Write("</Data></Cell>");
break;
default:
throw (new Exception(rowType.ToString() + " not handled."));

}
}


excelDoc.Write("</Row>");
}
excelDoc.Write("</Table>");
excelDoc.Write(" </Worksheet>");


}
excelDoc.Write(endExcelXML);
excelDoc.Close();
status = true;
// MessageBox.Show("Data exported to excel file successfuly");
}

catch (Exception)
{
status = false;// MessageBox.Show("Error in exporting data to excel file");
}
}
QuestionTableAdapter and Transactions. [modified] Pin
hdv2123-Mar-09 5:50
hdv2123-Mar-09 5:50 
QuestionError Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 3:45
Mustafa Ismail Mustafa3-Mar-09 3:45 
AnswerRe: Error Loading type during runtime Pin
Eddy Vluggen3-Mar-09 3:55
professionalEddy Vluggen3-Mar-09 3:55 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 3:59
Mustafa Ismail Mustafa3-Mar-09 3:59 
GeneralRe: Error Loading type during runtime Pin
Eddy Vluggen3-Mar-09 4:10
professionalEddy Vluggen3-Mar-09 4:10 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:11
Mustafa Ismail Mustafa3-Mar-09 4:11 
AnswerRe: Error Loading type during runtime Pin
J4amieC3-Mar-09 4:31
J4amieC3-Mar-09 4:31 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:38
Mustafa Ismail Mustafa3-Mar-09 4:38 
AnswerRe: Error Loading type during runtime Pin
Yusuf3-Mar-09 4:36
Yusuf3-Mar-09 4:36 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:39
Mustafa Ismail Mustafa3-Mar-09 4:39 
GeneralRe: Error Loading type during runtime Pin
Yusuf3-Mar-09 4:49
Yusuf3-Mar-09 4:49 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:52
Mustafa Ismail Mustafa3-Mar-09 4:52 
AnswerRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:55
Mustafa Ismail Mustafa3-Mar-09 4:55 
GeneralRe: Error Loading type during runtime Pin
Yusuf3-Mar-09 5:02
Yusuf3-Mar-09 5:02 
QuestionPanel Event Pin
Cliffer3-Mar-09 3:13
Cliffer3-Mar-09 3:13 
AnswerRe: Panel Event Pin
Calin Tatar3-Mar-09 3:34
Calin Tatar3-Mar-09 3:34 
GeneralRe: Panel Event [modified] Pin
Megidolaon4-Mar-09 2:30
Megidolaon4-Mar-09 2:30 

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.