Click here to Skip to main content
14,774,743 members
Home » Discussions » C#
   

C#

 
GeneralRe: Changing the properties of multiple labels in some kind of loop? Pin
Ron_UK16-Nov-20 6:40
MemberRon_UK16-Nov-20 6:40 
AnswerRe: Changing the properties of multiple labels in some kind of loop? Pin
Gerry Schmitz16-Nov-20 8:13
mveGerry Schmitz16-Nov-20 8:13 
QuestionHow to make a dll library? Pin
Alex Dunlop16-Nov-20 1:22
MemberAlex Dunlop16-Nov-20 1:22 
AnswerRe: How to make a dll library? Pin
Richard MacCutchan16-Nov-20 1:44
mveRichard MacCutchan16-Nov-20 1:44 
GeneralRe: How to make a dll library? Pin
Alex Dunlop16-Nov-20 1:47
MemberAlex Dunlop16-Nov-20 1:47 
GeneralRe: How to make a dll library? Pin
Richard MacCutchan16-Nov-20 1:51
mveRichard MacCutchan16-Nov-20 1:51 
AnswerRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 1:50
mveOriginalGriff16-Nov-20 1:50 
GeneralRe: How to make a dll library? Pin
Alex Dunlop16-Nov-20 2:51
MemberAlex Dunlop16-Nov-20 2:51 
I tried the following class code. Now, my problem is that "Rows" and "Columns" have red underline. They have not been defined in my class while I have used Microsoft Office Excel 16 object reference.
How can I sole those red underlines?
My updated code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DataGridView
{
    class ExcelExport
    {

        public void Export(string fileName, string DataSource,string FileName)
        {
            /*fileName is the name of the file will be written.
            DataSource is the DataGridView name used*/
            Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
            worksheet = workbook.Sheets["Sheet1"];
            worksheet = workbook.ActiveSheet;
            worksheet.Name = fileName;
            for (int i = 1; i < DataSource.Columns.Count + 1; i++)
            {
                worksheet.Cells[1, i] = DataSource.Columns[i - 1].HeaderText;
            }
            for (int i = 0; i < DataSource.Rows.Count; i++)
            {
                for (int j = 0; j < DataSource.Columns.Count; j++)
                {
                    worksheet.Cells[i + 2, j + 1] = DataSource.Rows[i].Cells[j].Value.ToString();
                }
            }
            var saveFileDialoge = new SaveFileDialog();
            saveFileDialoge.FileName = FileName;
            saveFileDialoge.DefaultExt = ".xlsx";
            if (saveFileDialoge.ShowDialog() == DialogResult.OK)
            {
                workbook.SaveAs(saveFileDialoge.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            }
        }
    }
}

GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 3:17
mveOriginalGriff16-Nov-20 3:17 
GeneralRe: How to make a dll library? Pin
Alex Dunlop16-Nov-20 3:25
MemberAlex Dunlop16-Nov-20 3:25 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 3:41
mveOriginalGriff16-Nov-20 3:41 
GeneralRe: How to make a dll library? Pin
Alex Dunlop16-Nov-20 3:48
MemberAlex Dunlop16-Nov-20 3:48 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 3:50
mveOriginalGriff16-Nov-20 3:50 
GeneralRe: How to make a dll library? Pin
Alex Dunlop16-Nov-20 4:09
MemberAlex Dunlop16-Nov-20 4:09 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 4:40
mveOriginalGriff16-Nov-20 4:40 
GeneralRe: How to make a dll library? Pin
Alex Dunlop16-Nov-20 5:15
MemberAlex Dunlop16-Nov-20 5:15 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 5:37
mveOriginalGriff16-Nov-20 5:37 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 6:41
mveOriginalGriff16-Nov-20 6:41 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 3:21
mveOriginalGriff16-Nov-20 3:21 
QuestionC# WPF MenuItem Control not working Pin
Member 783087415-Nov-20 10:01
MemberMember 783087415-Nov-20 10:01 
AnswerRe: C# WPF MenuItem Control not working Pin
Mycroft Holmes15-Nov-20 12:03
professionalMycroft Holmes15-Nov-20 12:03 
GeneralRe: C# WPF MenuItem Control not working Pin
Member 783087417-Nov-20 15:51
MemberMember 783087417-Nov-20 15:51 
QuestionHow to group an array list, within a list of records, Linq GroupBy Pin
jkirkerx14-Nov-20 14:29
professionaljkirkerx14-Nov-20 14:29 
AnswerRe: How to group an array list, within a list of records, Linq GroupBy Pin
Gerry Schmitz14-Nov-20 23:31
mveGerry Schmitz14-Nov-20 23:31 
QuestionA proper way to return a list (Xamarin, CollectionView, Realm) Pin
Member 1499286214-Nov-20 10:10
MemberMember 1499286214-Nov-20 10:10 

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.