Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.71/5 (5 votes)
See more:
hi,

I want to create a new excel file without using any file name and copy some data in excel file using c# ...pls help me on this.

pls help i realy need it

thank you
Posted
Updated 21-Oct-14 5:25am
v6
Comments
PIEBALDconsult 20-Oct-14 15:27pm    
You'd have to give it a name.
I'd use OleDb and the ACE engine, but you can also look into EPPLUS.
There are many ways.
TusharZoo 20-Oct-14 15:51pm    
thank you sir.

but i want to opan simple a new book.xlsx(ex. book1.xlsx if book1 are available then book2 will open etc) please help me..
BillWoodruff 20-Oct-14 17:45pm    
You are ignoring the feedback and solutions people are giving you. Start studying.

You cannot Open a new Excel file without file path, however you can create a new Excel file and write the data to it. There is a difference in both. Also note that you will always require to provide file path to open the file for working.

This article might help you to work with Excel using C#, Working with Excel Using C#[^]
 
Share this answer
 
Comments
TusharZoo 20-Oct-14 15:50pm    
thank you sir.

but i want to opan simple a new book.xlsx(ex. book1.xlsx if book1 are available then book2 will open etc) please help me..
Afzaal Ahmad Zeeshan 20-Oct-14 15:55pm    
Then just create a new file, don't open existing (since you don't want to pass the name) if you want to pass a name, then pass the name of the file to open. However, I am still confused, do you mean "create" by "open"?
TusharZoo 21-Oct-14 0:01am    
yes sir, i want to create a new excel file without passing file name ..pls help
Afzaal Ahmad Zeeshan 21-Oct-14 10:14am    
Then you can read the Article I posted, to learn how to create a new file. :)
TusharZoo 21-Oct-14 11:30am    
sir,i do not want to use any location ,path or file name
in your case
MyBook = MyApp.Workbooks.Open(DB_PATH);
i am new in excel coding
pls help me i realy need it
thank you
private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application xlApp ;
            Excel.Workbook xlWorkBook ;
            Excel.Worksheet xlWorkSheet ;
            object misValue = System.Reflection.Missing.Value;

            xlApp = new Excel.Application();
            xlWorkBook = xlApp.Workbooks.Open("csharp.net-informations.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            MessageBox.Show(xlWorkSheet.get_Range("A1","A1").Value2.ToString());

            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);
        }

        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Unable to release the Object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        } 
 
Share this answer
 
Comments
TusharZoo 20-Oct-14 15:50pm    
thank you sir.

but i want to opan simple a new book.xlsx(ex. book1.xlsx if book1 are available then book2 will open etc) please help me..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900