We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Running macros

Can i able to run macros using Xlsio?

3 Replies

VS Vikas Sekar Syncfusion Team March 10, 2015 06:20 AM UTC

Hi Matrostik,


Currently XlsIO has support only to preserve macros in the excel file. There is no support for running macros using XlsIO. But this requirement can be achieved by converting the macros in to C# code manually.


Please let me know if you have any other concerns.

Regards,
Vikas S




MA matrostik March 10, 2015 06:23 AM UTC

Can i have some example for it?

Thanks.


VS Vikas Sekar Syncfusion Team March 10, 2015 10:28 AM UTC

Hi Matrostik,

Please refer to the below XlsIO code snippets equivalent to the mentioned macro code. XlsIO either directly or by workaround will support most of the functionalities.

Macro Codes

Equivalent C# code using XlsIO

lastRow = [A65536].End(xlUp).Row

    int lastRow = GetXlRowTop(1, 65536, Sheets[0].Range["A65536"].IsBlank, Sheets[0]);

    private int GetXlRowTop(int coloumnIndex, int rowIndex, bool value, IWorksheet sheet)

    {

        for (int row = rowIndex; row >= 1; row--)

        {

            if ((sheet.Range[row, coloumnIndex].IsBlank != value))

            {

                return row;

            }

        }

        return 1;

    }

[A1:D4].ClearContents

    Range["A1:D4"].Clear(ExcelClearOptions.ClearContent);

[D3:DF3].SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=RC[1]"

[3:3] = [3:3].Value

   

    tempRange = Range["D3:DF3"];

    for (int cIndex = tempRange.Column; (cIndex <= tempRange.LastColumn); cIndex++)

    {

       if ((tempRange[3, cIndex].DisplayText == ""))

       {

         tempRange[3, cIndex].FormulaR1C1 = "=RC[1] ";

         tempRange[3, cIndex].Value = tempRange[3, cIndex].CalculatedValue;

       }

    }

[C:C].Replace What:="H/P", Replacement:="PUT"

    tempRangeCol = Worksheet.FindAll("H/P", ExcelFindType.Text);

    if (tempRangeCol != null)

    {

        for (int index = 0; (index  <= (tempRangeCol.Length - 1)); index++)

            {

                if ((tempRangeCol[index].Column == 3))

                {

                    tempRangeCol[index].Value = "PUT";

                }

            }

        }
    }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 Please let us know if you have any concerns.

Regards,

Vikas



Loader.
Live Chat Icon For mobile
Up arrow icon