Table export from .net AutoCAD command, exports random characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All, I have a .NET plugin, which is executed if user types the command. This .NET command exports the table rows and columns and put in a .csv, after that i convert into excel and upload in some external system.
Below .NET code exports for me the table rows and column, but it put some random characters. As you see below code, i had to hardcode so many things and my code is getting messier, as random characters keep coming. Can you please tell me how to ensure i can avoid those ? I understand newline characters users had put and i had no choice to replace newline, but for others i am surprised why the API's give this
Autodesk.AutoCAD.DatabaseServices.Table tb = (Autodesk.AutoCAD.DatabaseServices.Table)tr.GetObject(per.ObjectId, OpenMode.ForRead);
if (tb != null)
{
for (int i = 0; i < tb.Rows.Count; i++)
{
var s = "";
var z = "";
for (int j = 0; j < tb.Columns.Count; j++)
{
// Get the contents of our cell
var c = tb.Cells[i, j];
string pattern = @"{\\W\d.\d\d;";
string newstring = Regex.Replace(c.GetTextString(FormatOption.ForEditing), pattern, "");
string pattern1 = @"{\\W\d.\d;";
string newstring1 = Regex.Replace(newstring, pattern1, "");
string removalOfNewLine = Regex.Replace(newstring1, @"[\r\n]+", "");
z = removalOfNewLine.Replace("\\A1", "").Replace("#{\\H1x;", "#").Replace("}", "").Replace(@"{\H0.91667x;", "").Replace(@"{\H1x;\W0.7;", "").Replace(@"\H1x;", "").Replace(";", "");
var y = z + ";";
s = s + y;
}
sb.Append(s);
sb.AppendLine();
}
}