2017-03-28 27 views
1

私はInfragisticsのUltraGridウィジェットを使用してExcelライクなグリッドを作成しています。セルから値をコピーしてExcelに貼り付けようとしています。セルに含まれる実際の値(Valueプロパティ)の代わりに、セルに表示される値(Textプロパティ)がコピーされます。表示された値の代わりに、実際の値をコピーするオプションはありますか?UltraGridセルからExcelにEXACT値をコピーする方法

私は

PerformAction(UltraGridAction.Copy, false, false); 

を使用して、いくつかの方法や実際の値をコピーする方法を探して試してみたが、どれも見つからないしていません。私も独自のコピー機能を実装しようとしましたが、これはCSVデータを作成し、実際のセルをコピーしません。

void OnExportToClipboardSelectedRows(object sender, EventArgs e) 
    { 
     List<UltraGridRow> rows = this.Grid.GetAllSelectedRows().ToList(); 
     Console.WriteLine(rows[0].Cells.Count); 

     List<string> newRows = new List<string>(); 
     if (rows.Count > 0) 
     { 
      int minRowIndex = -1; 
      int maxRowIndex = -1; 

      foreach (var row in rows) 
      { 
       if (row.Index < minRowIndex || minRowIndex == -1) 
        minRowIndex = row.Index; 
       if (row.Index > maxRowIndex || maxRowIndex == -1) 
        maxRowIndex = row.Index; 
      } 

      List<int> selectedCols = new List<int>(); 
      foreach (var cell in this.Grid.Selected.Cells) 
      { 
       if (!selectedCols.Contains(cell.Column.Index)) 
        selectedCols.Add(cell.Column.Index); 
      } 

      for (int i = minRowIndex; i <= maxRowIndex; i++) 
      { 
       List<string> cells = new List<string>(); 
       foreach (int j in selectedCols) 
       { 
        cells.Add(this.Grid.Rows[i].Cells[j].Value.ToString()); 
       } 
       newRows.Add(String.Join("\t", cells)); 
      } 
      Clipboard.SetText(String.Join("\n", newRows)); 
     } 
     else 
     { 
      MessageBox.Show("No selected rows found."); 
     } 
    } 
+0

セルがフォーミュラの場合、その式をコピーするのではなく、その式をコピーしたいのですか? – krillgar

+0

Cell TextプロパティとValueプロパティの違いは何ですか? – Steve

+0

@krillgar実際、この問題は数式には関係しません。私は小数点の値(つまり-623.456213)を持っています。これは(623.456)として赤で表示されます。私は真価を求めます:-623.456213。現在、私は-623.456を取得します。 – Fejs

答えて

2

網羅的試験/エラー試みた後、私は最終的にワーキング溶液に来る:CellDisplayStylePlainTextに設定されている場合

var selectedCells = this.Grid.Selected.Cells; 

// Loop through selected cells and put them in "edit mode" (actually, show plain text) 
foreach (var cell in selectedCells) 
{ 
    Console.WriteLine(cell.CellDisplayStyle); 
    cell.CellDisplayStyle = CellDisplayStyle.PlainText;     
} 

// Execute copy command 
this.Grid.PerformAction(UltraGridAction.Copy, false, false); 

// Loop through selected cells and bring them back to original state 
foreach (var cell in selectedCells) 
{ 
    Console.WriteLine(cell.CellDisplayStyle); 
    cell.CellDisplayStyle = CellDisplayStyle.Default; 
} 

、細胞は実際の値ではなく、次にフォーマット値を表示します。その状態で、Copyを実行し、セルを元の状態に戻します。

関連する問題