Example #1
0
        private void StartBio2DAScan()
        {
            //dataGridView1.Rows.Clear();
            //dataGridView1.Columns.Clear();
            Table2DA = new Bio2DA(CurrentlyLoadedExport);
            //Add columns

            /*for (int j = 0; j < table2da.columnNames.Count(); j++)
             * {
             *  dataGridView1.Columns.Add(table2da.columnNames[j], table2da.columnNames[j]);
             * }
             *
             *
             * //Add rows
             * for (int i = 0; i < table2da.rowNames.Count(); i++)
             * {
             *  //defines row data. If you add columns, you need to add them here in order
             *  List<Object> rowData = new List<object>();
             *  for (int j = 0; j < table2da.columnNames.Count(); j++)
             *  {
             *      Bio2DACell cell = table2da[i, j];
             *      if (cell != null)
             *      {
             *          rowData.Add(cell.GetDisplayableValue());
             *      }
             *      else
             *      {
             *          rowData.Add(null);
             *      }
             *      //rowData.Add(table2da[i, j]);
             *  }
             *  dataGridView1.Rows.Add(rowData.ToArray());
             *  dataGridView1.Rows[dataGridView1.Rows.Count - 1].HeaderCell.Value = table2da.rowNames[i];
             * }
             *
             * //Add row headers
             * for (int i = 0; i < table2da.rowNames.Count(); i++)
             * {
             *  dataGridView1.Rows[i].HeaderCell.Value = table2da.rowNames[i];
             * }*/
        }
Example #2
0
        private void StartBio2DAScan()
        {
            dataGridView1.Rows.Clear();
            dataGridView1.Columns.Clear();
            table2da = new Bio2DA(export);
            //Add columns
            for (int j = 0; j < table2da.ColumnNames.Count(); j++)
            {
                dataGridView1.Columns.Add(table2da.ColumnNames[j], table2da.ColumnNames[j]);
            }


            //Add rows
            for (int i = 0; i < table2da.RowNames.Count(); i++)
            {
                //defines row data. If you add columns, you need to add them here in order
                List <Object> rowData = new List <object>();
                for (int j = 0; j < table2da.ColumnNames.Count(); j++)
                {
                    Bio2DACell cell = table2da[i, j];
                    if (cell != null)
                    {
                        rowData.Add(cell.GetDisplayableValue());
                    }
                    else
                    {
                        rowData.Add(null);
                    }
                    //rowData.Add(table2da[i, j]);
                }
                dataGridView1.Rows.Add(rowData.ToArray());
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].HeaderCell.Value = table2da.RowNames[i];
            }

            //Add row headers
            for (int i = 0; i < table2da.RowNames.Count(); i++)
            {
                dataGridView1.Rows[i].HeaderCell.Value = table2da.RowNames[i];
            }
        }
Example #3
0
        public static Bio2DA ReadExcelTo2DA(IExportEntry export, string Filename)
        {
            var          Workbook   = new XLWorkbook(Filename);
            IXLWorksheet iWorksheet = null;

            if (Workbook.Worksheets.Count() > 1)
            {
                try
                {
                    iWorksheet = Workbook.Worksheet("Import");
                }
                catch
                {
                    MessageBox.Show("Import Sheet not found");
                    return(null);
                }
            }
            else
            {
                iWorksheet = Workbook.Worksheet(1);
            }

            //Do we want to limit user to importing same column structure as existing?  Who would be stupid enough to do something else??? ME.
            // - Kinkojiro, 2019

            //STEP 1 Clear existing data
            Bio2DA bio2da = new Bio2DA();

            bio2da.export = export;

            //STEP 2 Read columns and row names

            //Column names
            IXLRow hRow = iWorksheet.Row(1);

            foreach (IXLCell cell in hRow.Cells(hRow.FirstCellUsed().Address.ColumnNumber, hRow.LastCellUsed().Address.ColumnNumber))
            {
                if (cell.Address.ColumnNumber > 1) //ignore excel column 1
                {
                    bio2da.ColumnNames.Add(cell.Value.ToString());
                }
            }

            //Row names
            IXLColumn column = iWorksheet.Column(1);

            foreach (IXLCell cell in column.Cells())
            {
                if (cell.Address.RowNumber > 1) //ignore excel row 1
                {
                    bio2da.RowNames.Add(cell.Value.ToString());
                }
            }

            //Populate the Bio2DA now that we know the size
            bio2da.Cells = new Bio2DACell[bio2da.RowCount, bio2da.ColumnCount];


            //Step 3 Populate the table.
            //indices here are excel based. Subtract two to get Bio2DA based.
            for (int rowIndex = 2; rowIndex < (bio2da.RowCount + 2); rowIndex++)
            {
                for (int columnIndex = 2; columnIndex < bio2da.ColumnCount + 2; columnIndex++)
                {
                    IXLCell xlCell         = iWorksheet.Cell(rowIndex, columnIndex);
                    string  xlCellContents = xlCell.Value.ToString();
                    if (!string.IsNullOrEmpty(xlCellContents))
                    {
                        Bio2DACell newCell = new Bio2DACell();
                        if (int.TryParse(xlCellContents, out int intVal))
                        {
                            newCell.Type = Bio2DACell.Bio2DADataType.TYPE_INT;
                            newCell.Data = BitConverter.GetBytes(intVal);
                        }
                        else if (float.TryParse(xlCellContents, out float floatVal))
                        {
                            newCell.Type = Bio2DACell.Bio2DADataType.TYPE_FLOAT;
                            newCell.Data = BitConverter.GetBytes(floatVal);
                        }
                        else
                        {
                            newCell.Type = Bio2DACell.Bio2DADataType.TYPE_NAME;
                            newCell.Pcc  = export.FileRef;                                                            //for displaying, if this displays before the export is reloaded and 2da is refreshed
                            newCell.Data = BitConverter.GetBytes((long)export.FileRef.FindNameOrAdd(xlCellContents)); //long because names are 8 bytes not 4
                        }
                        bio2da[rowIndex - 2, columnIndex - 2] = newCell;
                    }
                    else
                    {
                        bio2da.IsIndexed = true;  //Null cells = indexing
                    }
                }
            }
            return(bio2da);
        }