.NET

.NET

Reply
Contributor
17 Posts
0 Kudos
Registered: ‎04-20-2013
Post 1 of 6

dwg file in the excel file in c # winform transfer

443 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*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 2 of 6

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
17 Posts
0 Kudos
Registered: ‎04-20-2013
Post 3 of 6

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

05-03-2013 06:15 AM in reply to: Hallex
*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 4 of 6

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
17 Posts
0 Kudos
Registered: ‎04-20-2013
Post 5 of 6

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
762 Posts
100 Kudos
Registered: ‎03-21-2011
Post 6 of 6

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
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!