Exemple #1
0
		public override void Run()
		{
			var conn = new OriginConnection();
			conn.Connect(true);
			if (!conn.IsConnected())
				return;

			var list = new List<Tuple<string, Origin.WorksheetPage>>();
			ListAllWorksheetsInFolderAndSubfolders(conn.Application.RootFolder, string.Empty, list);

			int count = conn.Application.WorksheetPages.Count;
			for (int i = 0; i < list.Count; i++)
			{
				var path = list[i].Item1;
				var page = list[i].Item2;
				string name = page.Name;
				string lname = page.LongName;

				var newTable = new Altaxo.Data.DataTable();
				newTable.Name = path + (string.IsNullOrEmpty(lname) ? name : lname);
				string err = WorksheetActions.GetTable(page, newTable);
				if (null == err)
				{
					Current.ProjectService.CreateNewWorksheet(newTable);
				}
				else
				{
					Current.Gui.ErrorMessageBox(err);
				}
			}

			conn.Disconnect(false, null, false);
		}
Exemple #2
0
		public override void Run(Altaxo.Gui.Worksheet.Viewing.WorksheetController ctrl)
		{
			var comm = new OriginConnection();
			comm.Connect(true);
			comm.PutTable(ctrl.DataTable, false);
			comm.Disconnect(false, null, false);
		}
Exemple #3
0
		public override void Run(Altaxo.Gui.Worksheet.Viewing.WorksheetController ctrl)
		{
			var comm = new OriginConnection();
			comm.Connect(true);
			if (!comm.IsConnected())
				return;

			string err = comm.GetTable(ctrl.DataTable.Name, ctrl.DataTable);
			comm.Disconnect(false, null, false);

			if (err != null)
			{
				Current.Gui.ErrorMessageBox(err);
				return;
			}
		}
Exemple #4
0
        public static string GetTable(this OriginConnection conn, string originWorksheetName, Altaxo.Data.DataTable destTable)
        {
            if (!conn.IsConnected())
            {
                return("Not connected to Origin");
            }

            var app = conn.Application;

            Origin.WorksheetPage wbk;
            if (null == (wbk = app.WorksheetPages[originWorksheetName]))
            {
                return(string.Format("No origin worksheet named {0} found!", originWorksheetName));
            }

            return(GetTable(wbk, destTable));
        }
Exemple #5
0
		public override void Run()
		{
			var conn = new OriginConnection();
			conn.Connect(true);
			if (!conn.IsConnected())
				return;

			foreach (var table in Current.Project.DataTableCollection)
			{
				conn.PutTable(table, false);
			}

			conn.Disconnect(false, null, false);
		}
Exemple #6
0
        public static void PutTable(this OriginConnection conn, Altaxo.Data.DataTable srcTable, bool appendRows)
        {
            if (IsColumnReorderingNeccessaryForPuttingTableToOrigin(srcTable))
            {
                srcTable = (DataTable)srcTable.Clone();
                ReorderColumnsInTableForCompatibilityWithOrigin(srcTable);
            }

            var    stb        = new System.Text.StringBuilder();
            string strWksName = srcTable.ShortName;

            strWksName.Trim();
            // Validate worksheet name:
            if (0 == strWksName.Length)
            {
                ShowErrorMessage("Please specify a worksheet name first.");
                return;
            }

            int nColumns = srcTable.DataColumnCount;
            int nRows    = srcTable.DataRowCount;

            // Validate the number of columns and the number of rows:
            if (nColumns <= 0 || nRows <= 0)
            {
                ShowErrorMessage("Data table is empty, thus nothing needs to be copyied to Origin!");
                return;
            }

            var app = conn.Application;

            var originFolder = GetOrCreateFullFolderPath(app, srcTable.FolderName);
            var wbk          = GetOrCreateWorksheetPage(originFolder, strWksName);

            // for every group in our worksheet, make a separate origin worksheet

            var wks = wbk.Layers[0] as Origin.Worksheet;

            wks.ClearData();
            wks.Cols = 0;
            wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_LONG_NAME, true);

            // Set the column names

            for (int i = 0; i < srcTable.DataColumnCount; ++i)
            {
                var srcCol   = srcTable.DataColumns[i];
                var srcGroup = srcTable.DataColumns.GetColumnGroup(srcCol);

                Origin.Column col = wks.Columns.Add(srcTable.DataColumns.GetColumnName(i));
                col.LongName = srcTable.DataColumns.GetColumnName(i);

                if (srcCol is DoubleColumn)
                {
                    col.DataFormat = COLDATAFORMAT.DF_DOUBLE;
                    col.SetData((srcCol as DoubleColumn).Array);
                }
                else if (srcCol is DateTimeColumn)
                {
                    col.DataFormat = COLDATAFORMAT.DF_DATE;
                    col.SetData((srcCol as DateTimeColumn).Array);
                }
                else if (srcCol is TextColumn)
                {
                    col.DataFormat = COLDATAFORMAT.DF_TEXT;
                    col.SetData((srcCol as TextColumn).Array);
                }
                else
                {
                    throw new NotImplementedException("Type of column not implemented");
                }

                col.Type = AltaxoToOriginColumnType(srcTable.DataColumns.GetColumnKind(srcCol));
            } // end of loop for all data columns

            // now put the property columns to ORIGIN
            // note that ORIGIN has only special property columns
            // LongName (but this is set already), Units, Comments
            // and more generic property columns accessible by Parameter(0), Parameter(1) and so on

            var usedPropColIndices = new HashSet <int>();

            // Longname
            for (int i = 0; i < srcTable.PropCols.ColumnCount; ++i)
            {
                if (usedPropColIndices.Contains(i))
                {
                    continue;
                }
                if (IsLikeAnyOf(srcTable.PropCols.GetColumnName(i), LongNamePropertyColumnNames))
                {
                    usedPropColIndices.Add(i);
                    for (int j = 0; j < srcTable.DataColumnCount; ++j)
                    {
                        wks.Columns[j].LongName = srcTable.PropCols[i][j].ToString();
                    }
                    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_LONG_NAME, true);
                }
            }

            // Units
            for (int i = 0; i < srcTable.PropCols.ColumnCount; ++i)
            {
                if (usedPropColIndices.Contains(i))
                {
                    continue;
                }
                if (IsLikeAnyOf(srcTable.PropCols.GetColumnName(i), UnitPropertyColumnNames))
                {
                    usedPropColIndices.Add(i);
                    for (int j = 0; j < srcTable.DataColumnCount; ++j)
                    {
                        wks.Columns[j].Units = srcTable.PropCols[i][j].ToString();
                    }
                    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_UNIT, true);
                }
            }
            // Comments
            for (int i = 0; i < srcTable.PropCols.ColumnCount; ++i)
            {
                if (usedPropColIndices.Contains(i))
                {
                    continue;
                }
                if (IsLikeAnyOf(srcTable.PropCols.GetColumnName(i), CommentPropertyColumnNames))
                {
                    usedPropColIndices.Add(i);
                    for (int j = 0; j < srcTable.DataColumnCount; ++j)
                    {
                        wks.Columns[j].Comments = srcTable.PropCols[i][j].ToString();
                    }
                    wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_COMMENT, true);
                }
            }

            // other property columns

            for (int i = 0, k = 0; i < srcTable.PropCols.ColumnCount; ++i)
            {
                if (usedPropColIndices.Contains(i))
                {
                    continue;
                }
                usedPropColIndices.Add(i);
                for (int j = 0; j < srcTable.DataColumnCount; ++j)
                {
                    wks.Columns[j].Parameter[k] = srcTable.PropCols[i][j].ToString();
                }
                wks.set_LabelVisible(Origin.LABELTYPEVALS.LT_PARAM, true);
                ++k;
            }
        }