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
richard smith
1.4k
285
159.9k
C# to only run a block of code once
Mar 13 2013 3:45 PM
You guys may be able to tell me a better way to do this, but what I am wanting to do is I have a statement in my C# that creates a new instance of excel then codes...for example:
_Application docExcel = new Microsoft.Office.Interop.Excel.Application();
docExcel.Visible = true;
docExcel.DisplayAlerts = false;
_Workbook workbooksExcel = docExcel.ActiveWorkbook;
workbooksExcel = (_Workbook)(docExcel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet));
Worksheet worksheet = (Worksheet)docExcel.Worksheets["Sheet1"];
//more code down here to export datagrid to Excel
So with that being said, each time my function is called, I do not want it to run the above code, I only want it to run the above code if EXCEL IS NOT OPEN, OR this is the 1st time function is run. How can I do this in C#?
Reply
Answers (
9
)
updating datagrid in c' using oledb
how to make changes in app.config file.