Hi LSA,
Your query doesn't appear to be directly related to the Inventor API, it is rather Excel specific, so you may find more help on an Excel dedicated forum.
When you mention "I know it is possible to get the code to find the next empty cell, and the do something and then stop running untill next time it is activated.. but i haven't found out how to stop it..."
My suggestion would be to check if the cell content returns an empty string or not. However, since I'm not an Excel API expert, there might be a better way or a specific method in the Excel API to check a cell is empty.
Below is a C# code sample I was writting in order to export some list to Excel, you may find it useful:
private void ExcelExport()
{
try
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Excel Files (*.xls; *xlsx)|*.xlsx;*.xlsx";
sfd.Title = "Export to Excel format";
if (sfd.ShowDialog() == DialogResult.Cancel)
return;
Excel.Application app = new Excel.Application();
Excel.Workbook wb = app.Workbooks.Add(1);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
ws.Cells[1, 1] = _listViewEx.Columns[0].Text;
ws.Cells[1, 2] = _listViewEx.Columns[1].Text;
ws.Cells[1, 3] = _listViewEx.Columns[2].Text;
ws.Cells[1, 4] = _listViewEx.Columns[3].Text;
ws.Cells[1, 5] = _listViewEx.Columns[4].Text;
TreeNode rootNode = _treeView.Nodes[0];
int rowIdx = 2;
foreach (ListViewItem lvi in _listViewEx.Items)
{
ListViewItemTag tag = lvi.Tag as ListViewItemTag;
if (tag.TreeNode.Parent == rootNode)
{
++rowIdx;
}
int columIdx = 0;
foreach (ListViewItem.ListViewSubItem lvs in lvi.SubItems)
{
ws.Cells[rowIdx, ++columIdx] = lvs.Text;
}
CustomControls.LabeledProgressBar ctrl =
_listViewEx.GetEmbeddedControl(columIdx, lvi.Index) as
CustomControls.LabeledProgressBar;
if (ctrl != null)
ws.Cells[rowIdx, ++columIdx] = ctrl.LabelText;
++rowIdx;
}
object objMissing = System.Reflection.Missing.Value;
wb.SaveAs(sfd.FileName,
objMissing, objMissing, objMissing, objMissing, objMissing,
Excel.XlSaveAsAccessMode.xlExclusive,
objMissing, objMissing, objMissing, objMissing, objMissing);
wb.Close(objMissing, objMissing, objMissing);
app.Quit();
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show(
"Error during Excel export: " + ex.Message,
"Excel export error",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
Regards,
Philippe.
Philippe Leefsma
Developer Technical Services
Autodesk Developer Network