Click here to Skip to main content
15,909,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have a excelsheet having 2 sheet namely( Sheet1 name :dictionary, sheet 2 name :LimitWord), now in LimitWord i have 2 column (level and limit), and value level=1 and limit=0. Now using below code i want to update Limit file but it is not applying the changes and not giving error message also.

Please help me to find the solution.
int wordlimit=5
C#
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + FileName + " ;Persist Security Info=False;Extended Properties=Excel 8.0;";//FMT=Delimited(,)';

                string query = "Update [LimitWord$] set WordLimit=" + wordlimit + " where level= 1";

                objCon = new OleDbConnection(connString);
                cmmd = new OleDbCommand(query, objCon);
                objCon.Open();
                cmmd.CommandType = CommandType.Text;
                cmmd.ExecuteNonQuery();



Any help would be appreciated.

Thanks
AP
Posted
Updated 7-Jan-13 2:00am
v2

1 solution

for excel manipulation i use EPPlus.dll. its called Excel Package
you can download that file

its is quite simple to use

Im Pasting below a sample code that i took from one of my projects. Might be of help to you. it is unedited code

use this import statement

VB
Imports OfficeOpenXml
Sub ExcelOP(filename As String, countryCode As String, data As System.Data.DataTable)

        Using excelPackage As New ExcelPackage()

            Dim ws As ExcelWorksheet = excelPackage.Workbook.Worksheets.Add(countryCode)

            If data.Columns.Count <= 0 Then
                Label1.Text = "No Records"
            Else
                For l As Integer = 1 To data.Columns.Count - 1
                    ws.Cells(1, l).Value = HttpUtility.HtmlDecode(data.Columns(l).ToString)
                Next

                Using rng As ExcelRange = ws.Cells(1, 1, 1, data.Columns.Count - 1) 'ws.Cells("A1:K1")
                    rng.Style.Font.Bold = True
                    rng.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(192, 192, 192))
                End Using

                Dim totalRecords As Integer = data.Rows.Count

                For r As Integer = 0 To totalRecords - 1
                    For s As Integer = 1 To data.Columns.Count - 1
                        ws.Cells(r + 2, s).Value = HttpUtility.HtmlDecode(data.Rows(r)(s).ToString)
                    Next
                Next
                excelPackage.SaveAs(New FileInfo(filename))
                excelPackage.Dispose()
            End If
        End Using
    End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900