NIA BIM
NIA BIM

Reputation: 9

Create Multi excel Table for Each Worksheet by C#

hope be well.

I have multiple quantity take-off and each quantity has a specific worksheet. I faced error when I wanted to create the table for them The error was "Table name invalid" the code works for single worksheet.

 // Filter schedules to be exported
 foreach (ViewSchedule schedule in scheduleCollector.Cast<ViewSchedule>())
 {
     if (selectedSchedules.Contains(schedule.Name))
     {
         exportSchedules.Add(schedule);
     }
 }

 // Export schedules to Excel
 using (ExcelPackage package = new ExcelPackage())
 {
     foreach (var schedule in exportSchedules)
     {.
      .
      .
      .
      .
      .
      .
     }

 table(dataRange,worksheet, schedule.Name);
 private void table(ExcelRange dataRange, ExcelWorksheet worksheet,string schedulenametable)
 {
     // Create Excel Table
     var table = worksheet.Tables.Add(dataRange, schedulenametable);

     table.TableStyle = TableStyles.Light1; // Choose a table style

     // Auto-filter on headers
     table.ShowHeader = true;
     table.ShowFilter = true;
     table.ShowTotal = false;
 }

`

I really appreciated if you help me .

I also check the schedule.name with taskdialog and the resulat was unig name for each quantity but idk for multi table how is possible to do that?

Upvotes: -1

Views: 52

Answers (1)

egeer
egeer

Reputation: 1248

I think that your issue is that Revit Schedules can have characters in their names that are not allowed in Excel Tables.

Check out this link to Excel Documentation for allowed characters:

Important notes for names

Use valid characters — Always begin a name with a letter, an underscore character (_), or a backslash (). Use letters, numbers, periods, and underscore characters for the rest of the name.

Exceptions: You can’t use "C", "c", "R", or "r" for the name, because they’re already designated as a shortcut for selecting the column or row for the active cell when you enter them in the Name or Go To box.

Don’t use cell references — Names can’t be the same as a cell reference, such as Z$100 or R1C1.

Don’t use a space to separate words — Spaces cannot be used in the name. Consider how you can write the name using no spaces. Or, use an underscore character (_) or a period (.) as word separators. Examples: DeptSales, Sales_Tax or First.Quarter.

Maximum 255 characters — A table name can have up to 255 characters.

Use unique table names — Duplicate names aren’t allowed. Excel doesn’t distinguish between upper and lowercase characters in names, so if you enter “Sales” but already have another name called “SALES" in the same workbook, you’ll be prompted to choose a unique name.

Upvotes: 0

Related Questions