Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
favorite
I am trying to import the excel sheet in that we have block attributes. My requirement to import the sheet through command and then my c# code will fetch the block attributes values through sheet and design the block in Autocad save that drawing on system.

I need urgent solution.

What I have tried:

[CommandMethod("ElecOneLine1")]
     static public void ElecOneLine1()
     {
         string Path = Commands.SelectSpreadsheet();
         System.Data.DataTable table = Commands.ReadExcelToTable(Path);
         Commands.InsertBlocksCurrentDwg();
         Commands.DrawOneLineBackgroundCurrentDwg("OneLineBackground", 35.5478, 23.3750, 0, table.Rows[0]);
     }
     class Commands
     {
         [CommandMethod("LoadSpreadsheet")]
         static public string SelectSpreadsheet()
         {
             Document doc =
               Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
             Database db = doc.Database;
             Editor ed = doc.Editor;
             OpenFileDialog ofd =
               new OpenFileDialog(
                 "Select Excel spreadsheet to link",
                 null,
                 "xls; xlsx; xlsm",
                 "ExcelFileToLink",
                 OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles
               );
             System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
             if (dr != System.Windows.Forms.DialogResult.OK)
                 return null;
             ed.WriteMessage(
               "\nFile selected was \"{0}\".",
               ofd.Filename
             );
             return ofd.Filename;
         }
         public static System.Data.DataTable ReadExcelToTable(string path)
         {
             Workbook book = Workbook.Load(path);
             Worksheet sheet = book.Worksheets[0];
             return null ;
         }
Posted

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