Thursday, May 10, 2018

Online PDF to HTML5 Converter

Can't Install NuGet packages that require Newtonsoft.Json.10.0.1 in Visual Studio 2015

Simply remove the line that references Newtonsoft.Json in packages.config.
It will solve your problem.

Fix font-awesome webfont-woff2 Not Found


You need to add the mime type in the config file for woff2.


<system.webServer>
  <staticContent>
    <remove fileExtension=".woff2" />
    <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
  </staticContent>
</system.webServer>


ROUND() function in SQL SERVER


declare @i decimal(9,5),@d decimal(9,5)

set @i=21.4

set @d=21.5

select round(@i,0),round(@d,0)

Restrict Editing Header Footer in Word Document

1. Click On Restrict Editing
2. In the Restrict Editing pane, 
  •  Do not check the box under "1. Formatting restrictions",
  •  Do check the box under "2. Editing restrictions" and leave the drop down set to "No  changes (Read only)".
3. Select the entire body of the document (Ctrl+A).
4. In the Restrict Editing pane, check the box next to Everyone under the Exceptions section. 
5. Then start enforcing protection and save the template.
6. Basically, the "No changes" protection is applied only to the header and footer, the only parts that weren't selected when you checked "Everyone".

Thursday, May 3, 2018

Export to Excel using ClosedXML in ASP.Net


using System;
using System.Web.Mvc;
using JetSaveToursProject.Models;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using ClosedXML.Excel;

        public ActionResult ExportToXLSX(string CountryId, string Deliverystatus, string FromDate, string ToDate)
        {
            if (CountryId == null)
                CountryId = "";

            if (CountryId == "")
                CountryId = "0";

            if (Deliverystatus == null)
                Deliverystatus = "";

            if (FromDate == null)
                FromDate = "";

            if (FromDate.Trim() == "")
                FromDate = "01 jan 2000";

            if (ToDate == null)
                ToDate = "";

            if (ToDate.Trim() == "")
                ToDate = DateTime.Now.ToString("dd MMM yyyy");

            SqlDataAccessLayer sqlobj = new SqlDataAccessLayer();
            SqlParameter[] p = {
                    new SqlParameter("@ID", Convert.ToInt64(Session[eSession.ID.ToString()])),
                    new SqlParameter("@COUNTRY_ID",CountryId),
                    new SqlParameter("@CG_DELIVERYSTATUS",Deliverystatus),
                    new SqlParameter("@CG_ENTRY_DATE", FromDate),
                    new SqlParameter("@CG_END_DATE", ToDate)
            };
            DataTable dt = sqlobj.ExecuteDataset(CommandType.StoredProcedure, "ProcedureName", p).Tables[0];
            var aCode = 65;
            using (XLWorkbook wb = new XLWorkbook())
            {
                var ws = wb.Worksheets.Add("Summary");
                int rowIndex = 1;
                int columnIndex = 0;
                ws.ColumnWidth = 30;
                foreach (DataColumn column in dt.Columns)
                {
                    ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + columnIndex), rowIndex)).Value = column.ColumnName;
                    ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + columnIndex), rowIndex)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                    ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + columnIndex), rowIndex)).Style.Font.Bold = true;
                    ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + columnIndex), rowIndex)).Style.Font.FontSize = 13;
                    ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + columnIndex), rowIndex)).Style.Fill.BackgroundColor = XLColor.DodgerBlue;
                    ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + columnIndex), rowIndex)).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;

                    columnIndex++;
                }
                rowIndex++;
                foreach (DataRow row in dt.Rows)
                {
                    int valueCount = 0;
                    foreach (object rowValue in row.ItemArray)
                    {
                        ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + valueCount), rowIndex)).Value = rowValue;
                        ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + valueCount), rowIndex)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
                        ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + valueCount), rowIndex)).Style.Fill.BackgroundColor = XLColor.LightGray;
                        ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + valueCount), rowIndex)).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
                        ws.Cell(string.Format("{0}{1}", Char.ConvertFromUtf32(aCode + valueCount), rowIndex)).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;

                        valueCount++;
                    }
                    rowIndex++;
                }
                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "";
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;filename=Summary.xlsx");
                using (MemoryStream MyMemoryStream = new MemoryStream())
                {

                    wb.SaveAs(MyMemoryStream);
                    MyMemoryStream.WriteTo(Response.OutputStream);
                    Response.Flush();
                    Response.End();
                }
            }
            return View();
        }