Excel

  • I wasn't planning on covering this particular topic today, but then this comment came in overnight and I ended up taking a look into it. Paul has been trying to append a specific cell range to his connection string when creating a data-link for an Excel spreadsheet, adding to the code from this previous post. I gave it a try myself with a hardcoded cell range and it seemed to work fine, and so went ahead and modified the implementation of the TFS command to ask the user to enter their own cell range. What's probably most interesting about the…

  • Last week I received the following question from Adam Schilling: I have enjoyed your posts on .net programming for datalinks. I have searched high and low and haven't been able to find answers or any support to help me with a small issue.  My code (much of which was based off of your posts from 2007) works fine, except I cannot get it to use a different sheet from the workbook that is select.  Since the option to select a specific sheet is available when adding a link manually, I would think that it would be possible to programmatically do…

  • In the last post we saw some code to update an AutoCAD table linked to an Excel spreadsheet. In this post we go the other way, updating an Excel spreadsheet from a linked AutoCAD table. Here's the C# code: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Windows; namespace LinkToExcel {   public class Commands   {     [CommandMethod("T2S")]     static public void UpdateSpreadsheetFromTable()     {       Document doc =         Application.DocumentManager.MdiActiveDocument;       Database db = doc.Database;       Editor ed = doc.Editor;       PromptEntityOptions opt =         new…

  • Thanks to Viru Aithal, from DevTech India, for providing the code for this post (I converted the C# code below from some C++ he had sent to a developer). In the last post we showed how to create a table linked to an Excel spreadsheet using .NET in AutoCAD 2008. AutoCAD does a great job of looking for changes in the Excel spreadsheet, and asking whether you want to update the linked table: There may be times, however, when you want to force the update programmatically, whether from the spreadsheet to the table ot vice-versa. In this post we'll show…

  • In the last post I promised to tackle this issue, and so here we are again. 🙂 Note: the code in this post relies on enhanced table functionality introduced in AutoCAD 2008, so please don't get frustrated trying to make this work in previous versions. The following C# code follows on from yesterday's, taking the spreadsheet selected by the user and linking it to a newly-created table in the active AutoCAD drawing. I haven't bothered with line numbering in the below code, as it follows on almost exactly from the code shown last time (aside from renaming the namespace, the…