IOExcelWrite

Inheritance Hierarchy
  • Laga.IO
    • public class IOExcelWrite()
      • IOWrite_OpenExcelApp()
      • CloseSaveExcelApp()
      • CloseExcelApp()
      • CheckExcelFile()
      • IOWrite_NewExcelSheet()
      • IOWrite_SetActiveSheet()
      • IOWriteItem()
      • IOWriteList()
      • IOWriteMatrix()
    • Properties
      • XlRange
      • SheetNum
      • MatrixDataExcel
      • ListDataExcel


Class Constructor:
Syntax Parameters
IOExcelWrite(string FilePath, int SheetNumber) FilePath: The file name, SheetNumber: the excel sheet to write on
IOExcelWrite(bool display) display: in case you want to see the writing process and keep a live connection with excel
IOExcelWrite(string FilePath) FilePath: The file name


Methods

IOWrite_OpenExcelApp()

  • Description: Open an Excel document and display the document.
  • Parameters:
  • Return: void

Example


IOWrite_OpenExcelApp(bool display, int sheetNum)

  • Description: Open an Excel document based on the constructor.
  • Parameters:
    • bool: in case you want to see the writing process and keep a live connection with excel.
    • sheetNum: the excel sheet to write on.
  • Return: void

Example


IOWrite_OpenExcelApp(bool display)

  • Description: Open an Excel document based on the constructor.
  • Parameters:
    • bool: in case you want to see the writing process and keep a live connection with excel.
  • Return: void

Example


SaveCloseExcelApp(string Path)

  • Description: Save the Excel file and close safely the Excel application.
  • Parameters:
    • string: The file name.
  • Return: void

Example


CloseExcelApp(bool saveFile)

  • Description: Close safely the Excel application and decide to save or not.
  • Parameters:
    • bool: If true, the Excel file is saved.
  • Return: void

Example


CheckExcelFile(string path)

  • Description: Check if excel file exist.
  • Parameters:
    • string: The file name.
  • Return: bool

Example


IOWrite_NewExcelSheet(int pos, string name)

  • Description: Creates and excel sheet to write on.
  • Parameters:
    • int: the position of the sheet in the document.
    • string: the sheet name.
  • Return: void

Example

//making random data...
List<List<string>> lstString = new List<List<string>>();
int jagged;
Random rnd = new Random(DateTime.Now.Day);
for(int i = 0; i < 20; i++)
    {
    List<string> lstJagged = new List<string>();
    jagged = rnd.Next(10, 50);
    for(int j = 0; j < jagged; j++)
        lstJagged.Add(LagaTools.RandomChar(50, 90).ToString());
        
        lstString.Add(lstJagged);
    }
//stop making random data...

IOExcelWrite iOExcelWrite = new IOExcelWrite(true);
iOExcelWrite.IOWrite_NewExcelSheet(1, "testing");
iOExcelWrite.IOWriteMatrix(lstString, 1, 1, true);
iOExcelWrite.SaveCloseExcelApp(@"C:\Users\me\Documents\test.xlsx");
            
Console.ReadLine();

Results

Laga will create an excel file called test.xlsx in the specified address. The file will contain the Sheet1 and the sheet testing, defined in the code filled with the random data. It would be possible to see how the data is filled in the excel and how Laga, later on close the application.


IOWrite_SetActiveSheet(int pos)

  • Description: Activates a specific Excel sheet to write on.
  • Parameters:
    • int: The position of the excel sheet in the document.
  • Return: void

Example


IOWriteItem(string strItem, int Row, int Col)

  • Description: Write a single item in a excel sheet.
  • Parameters:
    • string: The item, value to write.
    • int: the row position.
    • int: the column position.
  • Return: void

Example


IOWriteList(List lstString, int Row, int Col, char dir)

  • Description: Write a list of strings in excel. The list length is calculated automatically.
  • Parameters:
    • List: The list of strings to write.
    • int: The row position.
    • int: The column position.
    • char: The writing direction, ‘c’ for top-down or ‘r’ for left-right
  • Return: void

Example


IOWriteMatrix(List> matData, int Row, int Col, bool swap)

  • Description: Write a nested list of strings in excel. The list length is calculated automatically.
  • Parameters:
    • matData[List>]: The nested list of strings to write.
    • Row[int]: The row position.
    • Col[int]: The column position.
    • swap[bool]: If true, write first the row. If false, write first the column.
  • Return: void

Example


Properties:

Excel.Range XlRange

  • Description: Get and Set an Excel range.

Example


int SheetNum

  • Description: Get the sheet number in use.

Example


List> MatrixDataExcel

  • Description: Set a nested list of strings.

Example


List ListDataExcel

  • Description: Set a list of strings.

Example



Revised documentation: 2019/06/14