I would recommend starting with using CSV files and not Excel if you're never done it before. It will be a lot easier to get up and running that way. Here's a sample I cobbled together using some code from the ScheduleCreation SDK sample and some other stuff I've written in the past. Tested it in a macro and it seems to work.
UIDocument uiDoc = this.ActiveUIDocument;
Document doc = uiDoc.Document;
string fileName;
System.Windows.Forms.OpenFileDialog openDlg = new System.Windows.Forms.OpenFileDialog();
openDlg.Title = "Select a file";
openDlg.Filter = "Comma Separated Values (*.csv)|*.csv|Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
openDlg.RestoreDirectory = true;
System.Windows.Forms.DialogResult result = openDlg.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
fileName = openDlg.FileName;
System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
//Create a filter to get all the title block types.
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.OfCategory(BuiltInCategory.OST_TitleBlocks);
collector.WhereElementIsElementType();
//Get ElementId of first title block type.
ElementId titleBlockId = collector.FirstElementId();
string csvLine = null;
Transaction t = new Transaction(doc, "Create Sheets");
t.Start();
while ((csvLine = sr.ReadLine()) != null)
{
char[] separator = new char[] { ',' };
string[] values = csvLine.Split(separator, StringSplitOptions.None);
// Make sure both values are valid
if(values[0] != null && values[0].Length > 0 && values[1] != null && values[1].Length > 0 )
{
ViewSheet sheet = ViewSheet.Create(doc, tbId);
sheet.Name = values[1];
sheet.SheetNumber = values[0];
}
}
t.Commit();
}