Dies ist mein Programm zum Öffnen einer Excel-Tabelle & programmgesteuert an einem angegebenen Punkt erstellen. Wenn ich (0,0) spezifiziere, fügt es die obere linke Ecke hinzu. Aber ich möchte die linke untere Ecke. Wie wäre der Code?Programmatisch hinzufügen (0,0,0) in Autocad 2015
Das ist mein Programm ..
[CommandMethod("exl")]
static public void TableFromSpreadsheet()
{
const string dlName = "Excel to Autocad";
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ofd = new OpenFileDialog("Select Excel Spreadsheet to Link", null, "xls; xlsx", "ExcelFileToLink", OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
var dr = ofd.ShowDialog();
if (dr != System.Windows.Forms.DialogResult.OK)
return;
ed.WriteMessage("\nFile selected was \"{0}\". Contains these sheets:", ofd.Filename);
var sheetNames = GetSheetNames(ofd.Filename);
if (sheetNames.Count == 0)
{
ed.WriteMessage("\nWorkbook doesn't contain any sheets.");
return;
}
for (int i = 0; i < sheetNames.Count; i++)
{
var name = sheetNames[i];
ed.WriteMessage("\n{0} - {1}", i + 1, name);
}
var pio = new PromptIntegerOptions("\nSelect a sheet");
pio.AllowNegative = false;
pio.AllowZero = false;
pio.DefaultValue = 1;
pio.UseDefaultValue = true;
pio.LowerLimit = 1;
pio.UpperLimit = sheetNames.Count;
var pir = ed.GetInteger(pio);
if (pir.Status != PromptStatus.OK)
return;
var ppr = ed.GetPoint("\nEnter table insertion point");
if (ppr.Status != PromptStatus.OK)
return;
var dlm = db.DataLinkManager;
var dlId = dlm.GetDataLink(dlName);
if (dlId != ObjectId.Null)
{
dlm.RemoveDataLink(dlId);
}
var dl = new DataLink();
dl.DataAdapterId = "AcExcel";
dl.Name = dlName;
dl.Description = "Excel 2 Autocad";
dl.ConnectionString = ofd.Filename + "!" + sheetNames[pir.Value - 1];
dl.DataLinkOption = DataLinkOption.PersistCache;
dl.UpdateOption |= (int)UpdateOption.AllowSourceUpdate;
dlId = dlm.AddDataLink(dl);
using (var tr = doc.TransactionManager.StartTransaction())
{
tr.AddNewlyCreatedDBObject(dl, true);
var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
var tb = new Table();
tb.TableStyle = db.Tablestyle;
tb.Position = ppr.Value;
tb.Cells.SetDataLink(dlId, true);
tb.GenerateLayout();
var btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(tb);
tr.AddNewlyCreatedDBObject(tb, true);
tr.Commit();
}
}
Ich glaube, dass diese Position fest ist und Sie die Position neu berechnen müssen, indem Sie die BoundingBox nach GenerateLayout verwenden. –
Ich würde mich freuen, wenn Sie mich über BoundingBox erklären. Danke im Voraus!!! –