TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
naga jyothi
NA
62
110.5k
how to return string with out using global variable in C#.net
Jul 20 2012 1:14 AM
string str; // using only global variable
private void path()
{
//code for save file dialog when Export to Excel,export to pdf button is clicked
try
{
saveFileDialog1.DefaultExt = "xls";
saveFileDialog1.Filter = "xls|*.xls|xlsx|*.xlsx";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
StreamWriter sw = new StreamWriter(saveFileDialog1.FileName);
str = saveFileDialog1.FileName;
sw.Flush();
sw.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnExport_Click(object sender, EventArgs e)
{
// For export EPF data in gridview to MS Excell
if (dgvEmployeeEPF.Rows.Count > 0)
{
try
{
Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
ExcelApp.Application.Workbooks.Add(Type.Missing);
ExcelApp.Columns.ColumnWidth = 20;
for (int i = 1; i < dgvEmployeeEPF.Columns.Count + 1; i++)
{
ExcelApp.Cells[1, i] = dgvEmployeeEPF.Columns[i - 1].HeaderText;
}
for (int i = 0; i <= dgvEmployeeEPF.Rows.Count - 1; i++)
{
for (int j = 0; j < dgvEmployeeEPF.Columns.Count; j++)
{
ExcelApp.Cells[i + 2, j + 1] = dgvEmployeeEPF.Rows[i].Cells[j].Value.ToString();
}
}
path();
if (saveFileDialog1.FileName != "")
{
ExcelApp.ActiveWorkbook.SaveCopyAs(str);
ExcelApp.ActiveWorkbook.Saved = true;
ExcelApp.Quit();
MessageBox.Show("Excel file created");
Process.Start(str);
}
btnExport.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("Report Not Found");
}
}
Reply
Answers (
2
)
Decorator pattern
how to move the data from one gridview to another gridview