Click here to Skip to main content
15,915,702 members
Home / Discussions / C#
   

C#

 
QuestionHow calculate Checksum for barcode code128 auto? Pin
Le@rner29-Oct-17 20:01
Le@rner29-Oct-17 20:01 
AnswerRe: How calculate Checksum for barcode code128 auto? Pin
Richard MacCutchan29-Oct-17 22:27
mveRichard MacCutchan29-Oct-17 22:27 
AnswerRe: How calculate Checksum for barcode code128 auto? Pin
Sascha Lefèvre29-Oct-17 22:27
professionalSascha Lefèvre29-Oct-17 22:27 
QuestionNo overload for method, error in c# file for Unity. Pin
Member 1349123628-Oct-17 14:33
Member 1349123628-Oct-17 14:33 
AnswerRe: No overload for method, error in c# file for Unity. Pin
Sascha Lefèvre28-Oct-17 14:47
professionalSascha Lefèvre28-Oct-17 14:47 
PraiseRe: No overload for method, error in c# file for Unity. Pin
Member 1349123628-Oct-17 15:25
Member 1349123628-Oct-17 15:25 
QuestionC# Problem extracting file from .zip created with DotNetZip Pin
manic_drummer28-Oct-17 11:58
manic_drummer28-Oct-17 11:58 
AnswerRe: C# Problem extracting file from .zip created with DotNetZip Pin
Sascha Lefèvre28-Oct-17 13:35
professionalSascha Lefèvre28-Oct-17 13:35 
AnswerRe: C# Problem extracting file from .zip created with DotNetZip Pin
Bernhard Hiller30-Oct-17 4:18
Bernhard Hiller30-Oct-17 4:18 
Questionc#Move music files in listbox up or down Pin
Member 1348924427-Oct-17 5:00
Member 1348924427-Oct-17 5:00 
AnswerRe: c#Move music files in listbox up or down Pin
Richard MacCutchan27-Oct-17 5:11
mveRichard MacCutchan27-Oct-17 5:11 
GeneralRe: c#Move music files in listbox up or down Pin
Member 1348924427-Oct-17 5:18
Member 1348924427-Oct-17 5:18 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan27-Oct-17 5:51
mveRichard MacCutchan27-Oct-17 5:51 
GeneralRe: c#Move music files in listbox up or down Pin
Member 1348924427-Oct-17 6:18
Member 1348924427-Oct-17 6:18 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan27-Oct-17 6:42
mveRichard MacCutchan27-Oct-17 6:42 
SuggestionRe: c#Move music files in listbox up or down Pin
Ralf Meier28-Oct-17 12:20
mveRalf Meier28-Oct-17 12:20 
GeneralRe: c#Move music files in listbox up or down Pin
Richard MacCutchan28-Oct-17 22:08
mveRichard MacCutchan28-Oct-17 22:08 
AnswerRe: c#Move music files in listbox up or down Pin
jschell27-Oct-17 7:39
jschell27-Oct-17 7:39 
AnswerRe: c#Move music files in listbox up or down Pin
Gerry Schmitz28-Oct-17 3:31
mveGerry Schmitz28-Oct-17 3:31 
Questionc# Need to be able to play music files that were additional items to the list box Pin
Member 1348924427-Oct-17 3:52
Member 1348924427-Oct-17 3:52 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
OriginalGriff27-Oct-17 3:57
mveOriginalGriff27-Oct-17 3:57 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
Richard Deeming27-Oct-17 4:04
mveRichard Deeming27-Oct-17 4:04 
GeneralSOLVEDRe: c# Need to be able to play music files that were additional items to the list box Pin
Member 1348924427-Oct-17 4:18
Member 1348924427-Oct-17 4:18 
AnswerRe: c# Need to be able to play music files that were additional items to the list box Pin
Gerry Schmitz27-Oct-17 4:26
mveGerry Schmitz27-Oct-17 4:26 
QuestionExporting result to .csv format instead of .xlsx without using interop.excel Pin
Ratsr26-Oct-17 23:54
Ratsr26-Oct-17 23:54 
Hello,
I am new to C# and has been assigned a task to modify a code.
One of our Reporting Tool is fetching the data from our Historian server and generating the report in excel format. But time taken for the generation of each report is around 15-20 mins depending upon the size of data. But this time should be less.
So, the developer of the Tool told us to try by our own exporting the data to .csv format. I tried it and changed the format to .csv but the time did not reduced.
I am attaching the part of our code:
private void export_to_excel(string template)
{

    try
    {

        //Creae an Excel application instance
        Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
        Microsoft.Office.Interop.Excel.Workbook excelWorkBook = excelApp.Workbooks.Open(path + "Report.xltx");
        Microsoft.Office.Interop.Excel.Worksheet excelWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelWorkBook.Sheets["Report"];
        string excelfile = IniReadValue("TemplateDetails", "ExpPath", SlTemplate.Text) + template +"_" + Fdt.Text.Replace('/', '_').Replace('-', '_').Replace(' ', '_').Replace(':', '_') + ".xlsx";
        object misValue = System.Reflection.Missing.Value;
        Microsoft.Office.Interop.Excel.Range range;
        int j = 0, k = 0, i = 0, l = 0,m=0;
        //Report one
        for (k = 0; k < dt.Rows.Count; k++)
        {
            i = 0;
            for (j = 0; j < dt.Columns.Count; j++)
            {
                if (stat == false)
                {
                    excelWorkSheet.Cells[9 + k, j + 2] = dt.Rows[k].ItemArray[j].ToString();
                }
                else
                {
                    if(j==0)
                    {
                        excelWorkSheet.Cells[9 + k, i + 2] = dt.Rows[k].ItemArray[j].ToString();
                    }
                    //else if (j % 2 != 0)
                    else if(dt.Columns[j].ColumnName.Contains("C"))
                    {

                            excelWorkSheet.Cells[9 + k, i + 3] = dt.Rows[k].ItemArray[j].ToString();
                            if (dt.Columns.Contains("C" + i.ToString()))
                            {
                                if (dt.Rows[k]["S" + i.ToString()].ToString().ToUpper() != "GOOD" & (dt.Rows[k]["S" + i.ToString()].ToString() != ""))
                                {
                                    range = excelWorkSheet.get_Range(Number2String(9 + k) + (k + 9).ToString(), Number2String(i + 3) + (k + 9).ToString());
                                    range.Cells.Font.Color = Microsoft.Office.Interop.Excel.XlRgbColor.rgbRed;
                                }
                            }

                        i++;
                    }
                }

            }
        }
        excelApp.DisplayAlerts = false;
        for (m = 4; m < ((j + 3)/2); m++)
        {
            if (m < j + 1)
            {
                //if (excelWorkSheet.Cells[9, k].Value.ToString() != "" & excelWorkSheet.Cells[9, k + 1].Value.ToString() != "")
                //{
                    if (excelWorkSheet.Cells[9, m].Value.ToString() == excelWorkSheet.Cells[9, m + 1].Value.ToString())
                    {
                        l++;
                    }

                    else
                    {
                        if (l > 0)
                        {
                            range = excelWorkSheet.get_Range(Number2String(m - l) + "9", Number2String(m) + "9");
                            range.Merge();
                            range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                        }
                        l = 0;
                    }
                //}
            }
            else
            {
                if (l > 0)
                {
                    range = excelWorkSheet.get_Range(Number2String(m - l) + "9", Number2String(m) + "9");
                    range.Merge();
                }
                l = 0;
            }
        }
        //excelWorkSheet.Cells[9, j + 3] = "REMARKS";
        excelWorkSheet.Cells[5, 5] = IniReadValue("TemplateDetails", "Substation", SlTemplate.Text);
        excelWorkSheet.Cells[6, 5] = IniReadValue("TemplateDetails", "Region", SlTemplate.Text);
        excelWorkSheet.Cells[7, 5] = Fdt.Text;
        string alph = "A";
        if(stat==false)
        {
            alph = Number2String(j + 1);
        }
        else
        {
            alph = Number2String(Convert.ToInt16(Math.Abs(Convert.ToDouble((j + 4) / 2))));
        }
        //string alph = Number2String(Convert.ToInt16(Math.Abs(Convert.ToDouble((j + 4) / 2))));
        //range = excelWorkSheet.get_Range("C36", alph + "40");
        range=excelWorkSheet.get_Range("B9", alph + (dt.Rows.Count + 8).ToString());
        range.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
        range = excelWorkSheet.get_Range("C12", alph + (dt.Rows.Count + 3).ToString());
        range.NumberFormat = "General";
        excelWorkSheet.Cells[12 + k, 1] = "Remarks:";
        range = excelWorkSheet.get_Range("A"+(12 + k).ToString() ,"E"+ (14 + k).ToString());
        range.Merge();
        for (j = 0; j < pntid.Count; j++)
        {
            excelWorkSheet.Cells[49+j, 2] = DGSet[j];
            excelWorkSheet.Cells[49+j, 3] = dgval[j];
            excelWorkSheet.Cells[49+j, 2].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
            excelWorkSheet.Cells[49+j, 3].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
        }
        range = excelWorkSheet.get_Range("B49", "C"+ (49+j-1).ToString());
        range.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
        range.VerticalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
        range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
        //range.Cells.Font.Background = Microsoft.Office.Interop.Excel.XlRgbColor.rgbYellow;
        range.Cells.WrapText = true;

        range = excelWorkSheet.get_Range("B49");
        range.EntireColumn.AutoFit();
        //range.Columns.AutoFit();

        excelWorkSheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlPortrait;
        excelWorkSheet.PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA3;



            Microsoft.Office.Interop.Excel.Worksheet excelWorkSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)excelWorkBook.Sheets["Chart"];
            if (graph.Checked == true)
            {
                Microsoft.Office.Interop.Excel.ChartObject chartObject11 = (Microsoft.Office.Interop.Excel.ChartObject)excelWorkSheet1.ChartObjects(1);
                chartObject11.Activate();
                Microsoft.Office.Interop.Excel.Chart chartPage = chartObject11.Chart;
                //range = excelWorkSheet.get_Range("B9", alph + (dt.Rows.Count+3).ToString());

                //chartPage.SetSourceData(range);

                range = excelWorkSheet.get_Range("B9", alph + (dt.Rows.Count + 3).ToString());

                excelApp.ActiveChart.SetSourceData(range, Microsoft.Office.Interop.Excel.XlRowCol.xlColumns);
                //excelApp.ActiveChart.PlotBy = Microsoft.Office.Interop.Excel.XlRowCol.xlRows;
                excelWorkSheet1.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlPortrait;
                excelWorkSheet1.PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA3;
            }
            else
            {
                excelWorkSheet1.Visible = Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetHidden;
            }
        //excelApp.DisplayAlerts = false;
        excelWorkBook.SaveAs(excelfile, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
        excelWorkBook.Close();
        excelApp.Quit();
        releaseObject(excelWorkSheet);
        releaseObject(excelWorkBook);
        releaseObject(excelApp);
        //success = 1;
        foreach (Process clsProcess in Process.GetProcesses())
        {
            if (clsProcess.ProcessName.Equals("EXCEL"))  //Process Excel?
                clsProcess.Kill();
        }
    }
    catch (Exception err)
    {
        fail = fail+1;
        ErrorLog(DateTime.Now.ToString() + "----- Export to excel ---" + err.ToString()); ;
    }
}

Can anyone please help me getting out of the situation with or without using interop.excel.

Thanks in Advance,
Rohit

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.