Forum Post: RE: Two-dimensional Array from .net

  • Thread starter Thread starter Mike Fechner
  • Start date Start date
Status
Not open for further replies.
M

Mike Fechner

Guest
/********************************************************************** * Copyright (C) 2006-2012 by Consultingwerk Ltd. ("CW") - * * www.consultingwerk.de and other contributors as listed * * below. All Rights Reserved. * * * * Software is distributed on an "AS IS", WITHOUT WARRANTY OF ANY * * KIND, either express or implied. * * * * Contributors: * * * **********************************************************************/ /*------------------------------------------------------------------------ File : Consultingwerk.Utilities.Support.ExcelHelper Purpose : Helper classes for communicating with MS Excel through COM-Interop Syntax : Static methods Description : The GUI for .NET AVM bridge does not support accessing multi-dimensional .NET Collections or Array's. These helper routines are designed to workaround the ABL restriction Author(s) : Mike Fechner / Consultingwerk Ltd. Created : Sun Feb 26 22:14:38 CEST 2012 Notes : ----------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Interop.Excel; namespace Consultingwerk.Utilities.Support { public class ExcelHelper { /*------------------------------------------------------------------------------ Purpose: Returns a single cell value Notes: @param poWorksheet The reference to the Microsoft.Office.Interop.Excel.Workshop instance @param piRow The row index @param piCell The cell index @return The System.Object value of the cell ------------------------------------------------------------------------------*/ public static System.Object GetExcelCellValue (Worksheet poWorksheet, int iRow, int iCell) { return ((Range)poWorksheet.Cells[iRow, iCell]).Value; } /*------------------------------------------------------------------------------ Purpose: Returns multiple values from row in a Excel worksheet Notes: @param poWorksheet The reference to the Microsoft.Office.Interop.Excel.Workshop instance @param piRow The row index @param values An Object[] to be populated with values ------------------------------------------------------------------------------*/ public static void GetExcelCellValues(Worksheet poWorksheet, int iRow, ref Object[] values) { int i; for (i = 0; i values.Length; i++) { values = ((Range)poWorksheet.Cells[iRow, i + 1]).Value; } } /*------------------------------------------------------------------------------ Purpose: Assigns a single cell value Notes: @param poWorksheet The reference to the Microsoft.Office.Interop.Excel.Workshop instance @param piRow The row index @param piCell The cell index @param The System.Object value that should be assigned to the cell ------------------------------------------------------------------------------*/ public static void SetExcelCellValue(Worksheet poWorksheet, int iRow, int iCell, Object oValue) { ((Range)poWorksheet.Cells[iRow, iCell]).Value = oValue; } /*------------------------------------------------------------------------------ Purpose: Assigns multiple cell values from an Object [] Notes: @param poWorksheet The reference to the Microsoft.Office.Interop.Excel.Workshop instance @param piRow The row index @param The System.Object[] with the values that should be assigned to the cells in that row ------------------------------------------------------------------------------*/ public static void SetExcelCellValues(Worksheet poWorksheet, int iRow, Object[] oValues) { int i; for (i = 0; i oValues.Length; i++) { ((Range)poWorksheet.Cells[iRow, i + 1]).Value = oValues; } } } }

Continue reading...
 
Status
Not open for further replies.
Back
Top