.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
Reply
Message 1 of 2
ugur35
806 Views, 1 Reply

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

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?
1 REPLY 1
Message 2 of 2
fenton.webb
in reply to: ugur35

I recommend you cut down this post into smaller posts




Fenton Webb
AutoCAD Engineering
Autodesk

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost