.NET

.NET

Reply
Contributor
ugur35
Posts: 17
Registered: ‎04-20-2013
Message 1 of 6 (439 Views)

dwg file in the excel file in c # winform transfer

439 Views, 5 Replies
05-03-2013 03:31 AM

 How can I dwg file in the excel file in c # winform transfer? 

Good Times

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 6 (423 Views)

Re: dwg file in the excel file in c # winform transfer

05-03-2013 05:03 AM in reply to: ugur35
Try language translator please:
http://translate.google.com/
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
ugur35
Posts: 17
Registered: ‎04-20-2013
Message 3 of 6 (395 Views)

Re: dwg file in the excel file in c # winform transfer

05-03-2013 06:15 AM in reply to: Hallex
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 6 (376 Views)

Re: dwg file in the excel file in c # winform transfer

05-03-2013 07:36 AM in reply to: ugur35

Ok, that make a sence,

then try this code, but change before Excel file name,

shhet name and range address:

 

Require references to:
Microsoft Excel 12.0 Object Library
and
Microsoft Office 12.0 Object Library
//--------------------------------------------//
#region "Imports"
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Windows.Forms;
#endregion

     public static void ReadExcel()
        {
            // set file name to read:
            string xlFileName = @"c:\Test\dummy.xls";
            Excel.Application xlApp;
            Excel.Workbook xlBook;
            Excel.Sheets xlSheets;
            Excel.Worksheet xlSheet;
            Excel.Range xlRange;
            // get Excel application
            xlApp = new Excel.Application();

            xlApp.Visible = false;
            object miss = Type.Missing;
            StringBuilder sb = new StringBuilder();
            try
            {
                // try open workbook as read-only
                xlApp.Workbooks.Open(xlFileName, false, true, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss);
                xlBook = xlApp.ActiveWorkbook;
                xlBook.Saved = true;
                xlApp.DisplayAlerts = false;
                xlSheets = xlBook.Worksheets;
                // few ways to get an Excel sheet
                // get sheet by name:
                // xlSheet = (Excel.Worksheet)xlSheets.Item["Big Sheet"];
                // get sheet by index:
                xlSheet = (Excel.Worksheet)xlSheets.Item[1];
                // get sheet by name:
                // xlSheet = (Excel.Worksheet)xlSheets.get_Item("Big Sheet");
                 // get sheet by index:
                // xlSheet = (Excel.Worksheet)xlSheets.get_Item(1);
                // few ways to get an Excel range
                // xlRange = (Excel.Range)xlSheet.Range[xlSheet.Cells[1, 1], xlSheet.Cells[5, 6]]; 
                // the same as:
                xlRange = (Excel.Range)xlSheet.Range["A1:F5"];//	<-- change range address here
                // read the whole range:
                //object[,] varr = (object[,])xlRange.Value2;
                // the same as:
                object[,] varr = (object[,])xlRange.Value;
                // get sizes of arrary:
                int i = varr.GetUpperBound(0);
                int j = varr.GetUpperBound(1);
                // loop thru array
                for (int a = 0; a < i; a++)
                {
                    Excel.Range xlCell;

                    string cell = "";
                    for (int b = 0; b < j; b++)
                    {
                        //cell index in Excel is non zero-based and starts from 1 
                        xlCell = (Excel.Range)xlRange.Item[a + 1, b + 1];
                        cell = cell + xlCell.Value.ToString() + "\t";
                    }
                    // populate stringbuilder
                    sb.AppendLine(cell);
                }


            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
            finally
            {
                // close all workbooks
                xlApp.Workbooks.Close();
                // quit application
                xlApp.Quit();
                MessageBox.Show(sb.ToString());
            }
        }

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
ugur35
Posts: 17
Registered: ‎04-20-2013
Message 5 of 6 (286 Views)

Re: dwg file in the excel file in c # winform transfer

05-18-2013 01:40 AM in reply to: Hallex

thank you very much

But data in dwg file

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 6 of 6 (219 Views)

Re: dwg file in the excel file in c # winform transfer

05-23-2013 04:34 AM in reply to: ugur35

I have replied to your other post on this topic. The code snippet that I have posted is very minimal and you can get more details on using the Excel API from code snippet that Hallex has shared.

 

http://forums.autodesk.com/t5/NET/I-want-to-read-data-from-a-DWG-excel-file-using-C/m-p/3933417#M351...

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.