.NET

.NET

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

I want to read data from a DWG excel file using C sharp

319 Views, 1 Replies
07-05-2013 01:41 AM

example code:

[CommandMethod("Test")]
public static void TestMethod()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;

    using (Transaction Tx = db.TransactionManager.StartTransaction())
    {
        BlockTableRecord bt = Tx.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;

        foreach (ObjectId id in bt)
        {
            if (id.ObjectClass.Name != "AcDbOle2Frame")
                continue;

            Ole2Frame oleFrame = Tx.GetObject(id, OpenMode.ForRead) as Ole2Frame;

            if (! oleFrame.IsLinked)
            {
                Microsoft.Office.Interop.Excel.Workbook wb = oleFrame.OleObject as Microsoft.Office.Interop.Excel.Workbook;

                Microsoft.Office.Interop.Excel.Worksheet ws = wb.ActiveSheet;

                Microsoft.Office.Interop.Excel.Range range = ws.UsedRange;
                for (int row = 1; row <= 15; row++)
                {
                    for (int col = 1; col <= range.Columns.Count; col++)
                    {
                        ed.WriteMessage(String.Format("{0}{1}{2}-{3}", Environment.NewLine, row, col, Convert.ToString((range.Cells[row, col] as Microsoft.Office.Interop.Excel.Range).Value2)));
                    }
                }
            }
        }
    }


1-autocad program will be closed
2-be selected within the file path c sharp example: csharp.jpg
3-I want to read data from a DWG excel file using C#. examples: dwgfile.jpg and drawing1.dwg
4-I want to list here DataGridView data
5-c sharp winform .net 4.0
Can you help me?
ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 2 (248 Views)

Re: I want to read data from a DWG excel file using C sharp

07-10-2013 02:35 PM in reply to: ugur35

I recommend you cut down this post into smaller posts





Fenton Webb

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.