Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, 27 March 2020

How to create Excel file in C#

Hi developers, the article is all about the development of an Excel file. And if you ask me how excited I am working on Excel, frankly I always try to walk away from these reporting kinds of development tasks. But it’s life and you can’t hide. So, folks, I have structured and well prepared this excel development series that will work out for everyone and in any situation. As far as I am concern about creating Excel file using C#, I will suggest a developer should proceed with below two options: -
  • Using Microsoft.Office.Interop.Excel library
  • Using EPPlus library (Mostly Recommended)
I will go through both the Excel development library options one by one.


In this blog, we will go step by step to create Excel with option 1.

Microsoft.Office.Interop.Excel

About
C# by default gives this library under a set of Microsoft Office libraries by which you can access other Office Objects like Excel, Word, InfoPath, Access, MS Project, OneNote, Outlook, PowerPoint, Publisher, SharePoint, Visio, and SmartTag.

Create a new Console Application
1. Open Visual Studio.
2. Create a New Console Application (.NET Framework).
3. Type a name for your project in the Name field.

Click OK.

The new project appears in Solution Explorer.

Add References
In Solution Explorer, right-click on your references folder and then click Add Reference. The Reference Manager dialog box appears.

Select the Assemblies tab on left, select Microsoft.Office.Interop.Excel. Click OK.

Practical Implementations

1.    Open the Program.cs/Class1.cs file.
2.    Add the below namespace before start developing an Excel file.

using Excel = Microsoft.Office.Interop.Excel;

3.    Your complete code will look like this:

using System;
using System.Runtime.InteropServices;

using Excel = Microsoft.Office.Interop.Excel;

namespace DemoConsoleApplication
{
    public class CreateExcelFileUsingMicrosoftOffice
    {
        public static void Main(string[] args)
        {
            Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            xlWorkSheet.Cells[1, 1] = "Call";
            xlWorkSheet.Cells[1, 2] = "Company";
            xlWorkSheet.Cells[1, 3] = "Contact";
            xlWorkSheet.Cells[1, 4] = "Phone";
            xlWorkSheet.Cells[2, 1] = "1";
            xlWorkSheet.Cells[2, 2] = "2ML Real Estate";
            xlWorkSheet.Cells[2, 3] = "Max Louis";
            xlWorkSheet.Cells[2, 4] = "(4655767)98-876";
            xlWorkSheet.Cells[3, 1] = "2";
            xlWorkSheet.Cells[3, 2] = "100 Club of Houston";
            xlWorkSheet.Cells[3, 3] = "Rick Robert";
            xlWorkSheet.Cells[3, 4] = "(565767)798-876";

            xlWorkSheet.Columns[1].AutoFit();
            xlWorkSheet.Columns[2].AutoFit();
            xlWorkSheet.Columns[3].AutoFit();
            xlWorkSheet.Columns[4].AutoFit();

            xlWorkSheet.Rows[1].Font.Bold = true;

            xlWorkBook.SaveAs("E:\\DemoMSInteropCSharpExcel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            Marshal.ReleaseComObject(xlWorkSheet);
            Marshal.ReleaseComObject(xlWorkBook);
            Marshal.ReleaseComObject(xlApp);

            Console.WriteLine("Excel file created , you can find the file E:\\DemoMSInteropCSharpExcel.xls");
        }
    }
}


Output

Call
Company
Contact
Phone
1
2ML Real Estate
Max Louis
(4655767)98-876
2
100 Club of Houston
Rick Robert
(565767)798-876

  
Related Questions:


Ques- What does Marshal.ReleaseComObject() does?
Ans- The Marshal.ReleaseComObject() decrement the reference count of the Runtime Callable Wrapper (RCW) associated with the specified Component Object Model (COM) object.

Ques- What is Runtime Callable Wrapper (RCW)?
Ans- It is an object generated by CLR in order to allow a COM object to be accessed from managed code. Its functions are to pass data and marshal calls between COM object and .NET client.

Hope you find the article helpful and interesting. 

For any query, comment us below.



Click imagination hunt to read latest blogs.

Posted By – Manish Kumar Gautam
Read More »

Thursday, 26 March 2020

How to make your life easy and happy in this lockdown time


Life is the best creature of God; don’t make it tough, live your life like this is the best time for you and your family. Maybe, you will not get this chance second time in your life so, please STAY HOME and STAY SAFE. 


Family is the most important thing, so this is the Golden time for you to make it the best time of life. Spend time with them rather than using a phone all day. When everyone leaves you, your family is the one who always stays by your side. This is the time to make them feel how much thank full you are.


Do some funny things at home, make your family happy in this crucial time when the whole world is troubling with coronavirus problems so, it’s your duty to don’t be panic this time. I think God gave us the chance to spend time with your loved ones like mother, father, sisters, brothers, friends, and others.

Neelam's Tips for Self-Love and Success

1. Try to cook new food for your family - we become very busy in our life and cannot do all this stuff despite knowing that this small happiness can become delightful moments for our family.

2. Listen to your favorite songs and sing it loud to make your soul happy.

3. Give morning hug to your family members, this is the best way to show your love and care to your family and I would say that we should always do this also in working days too. 


4. Have device-free lunch and dinner with your family. Convince, people to keep aside their devices and have a meal connecting with only the people sitting at the table.

5. Know what makes you blissed out and on cloud nine, do it more often. Does dancing put you in a good mood? So, do that every day because it’s the best way to convey emotions.

6. Do 20 Jumping Jacks. This easy, do-anywhere exercise is sure to give you a quick energy boost and gets the blood flowing. It also helps to get the creative juices flowing, so it’s a great break to take during work or when feeling stuck on a project. 


7. Learn to draw, play an instrument or learn a language. Learning helps build self-confidence and feeds creativity. Read Novels if you like reading books.

8. Watch the sunrise or sunset. And remember, if something didn’t work out today, we need to try again and try harder the next time. And once this corona problem will go away from our life, everything will come to normal, always hopes for best. 


Hope you find the article interesting... 

Comment us your way to make life easy.



Click imagination hunt to read the latest blogs.

Posted By - Neelam Saroj

Read More »

Tuesday, 7 January 2020

How to Live a beautiful life with challenges – Get Motivated


Life is a very beautiful thing. What makes life so unique and so beautiful? It is beautiful because whatever you have that you may be facing, what you may be dealing with. Life is still good.


Life has so many phases but life is always good. Every day is a new day and another opportunity that may not have. This life that you have been given, this life, that you are temporary holding on to, This life that has been given to you for only important reasons has more meaning than can you ever imagine. So many people In the world take life for granted instead of realizing that you have to take the opportunity to live it the best way you know-how.

Now on this journey of life, you’re going to face a significant amount of circumstances, a different amount of challenges in some you’re going to fall into areas that you cannot understand and may’ be it’s not in the position for you to understand but when that moment comes, when you understand to feel that you are in the position that you don’t love your life, then shame on you, because your life is a beautiful thing and no deserve to ruin it, no one deserves to control it and no one deserves to steal your joy.

Your life is your life and you have the right to live it in the best way you can. You can discipline yourself according to the situation and take full control and responsibility for the outcome of whatever it is that you are seeking at this moment. There are going to be so many different things that you embark on, that’s going to try to slow you down and that you must face but instead from running from problems, run towards problems. Try to understand that life has meaning, it has a reason and all of these things that you may be thinking that is so hard on you. Just remember sometimes you’re going to have to go through these changes, these circumstances that outs you in a position that makes you feel you’re not worthy anymore But make no mistakes, you are worthy, You are created for something, You didn't create for anything.


Life has a gift. A gift of giving and receiving, and whether it’s good or bad. You got to make sure you understand, these challenges have to happen in your life. You will come to a point that you feel focusing on the things that you have control of in life. Believe in Yourself and know that it is not over for you.

#motivation #dailymotivation #imaginationhunt #life

Read More »

Monday, 6 January 2020

High Voltage System - Reason for having High Voltage System On board ships


As we already know about the voltages used onboard a ship. It is usually a 3phase, 60Hz, 440 Volts supply being generated and distributed onboard ship.

  1. Higher power requirement on board ship is the foremost reason for the evolution of HV in ships.
  2. Higher power requirement has been necessitated by development of larger vessel required for containers transport particularly reefers containers and cruise vessels.
  3. Gas carriers needing extensive cargo cooling electric propulsion.
  4. For a ship with large electrical power demand, it is necessary to utilize the benefits of a high voltage installation.


The design benefits relate to the simple ohms laws relationship that current (for a given power) is reduced as the voltage is increased. Working at high voltage onboard ship significantly reduces the relative overall size and weight of electrical power equipment.



When Heavy loads are connected to the Low voltage system the magnitude of current flow becomes too large resulting in overheating due to high iron and copper losses.

P = V * I * COS(Φ)

Copper losses = I^2 * R (KW)

Already High Voltage levels of 3.3 KV, 6.6 KV and 11 KV are regularly employed ashore for regional power distribution and industrial motor drives.

For example, a motor (let us assume a bow thruster), maybe a smaller size if it designed to operate on 6600 Volts. For the same power, the motor would be of a smaller size if is designed for 6600 Volts when compared to 440 Volts.

Thus these are the major reasons why recent ships have shifted towards the high voltage systems. The main disadvantage Highlighted by the owner, when working in an HV installation, is the very necessary adherence to stringent safety procedures.

Advantages:

  1. For a given power, higher Voltage means Lower current, resulting in:
  2. Reduction in size of generators, motors, cables, etc.
  3. Saving of space and weight.
  4. Ease of Installation.
  5. Reduction in cost of Installation.
  6. Lower losses- more efficient utilization of generated power.
  7. Reduction in short circuit levels in the system which decides the design and application of the electrical equipment used in the power system.


Disadvantages:

  1. Higher Insulation Requirements for cables and equipment used in the system.
  2. Higher risk factor and the necessity for strictly adherence to stringent safety procedures.




Read More »

Wednesday, 13 November 2019

Top Mid Cap Mutual Funds

Today we compare “Thematic Infrastructure” Mutual Fund with their yearly returns. We daily update returns of the best mutual fund in industry. As we earlier discuss Small and mid-cap mutual fund and Pure Large Cap mutual fund. 

Mutual funds are among the best favorites with all investor. Today Investing in the mutual fund is highly recommended by direct companies or brokers. As said, "Start Investing early for better wealth creation."



Top Pure Mid Cap Mutual Fund (As on 13th Nov 2019)

A. Axis Midcap fund: 
5 Year return-13.68 %.

B. DSP Midcap Fund:
5 Year return-10.3 %.

C. Tata Midcap Fund: 
5 Year return-8.55 %.

D. Kotak Emerging Equity fund: 
5 Year return-9.99 %. 

E. Invesco India Midcap fund:
5 Year return- 9.73%.




For any query, comment us below.



Click imagination hunt to read latest blogs.


Keep learning and sharing...
Read More »

Thursday, 31 October 2019

Electro Technical Officer(ETO) Exam Questions

Examination of Electrical Technical Officer
(Marine Electrotechnology and SSEP)

1. Explain three methods of overcurrent protection for electrical circuits. Explain with the aid of the diagram, the meaning of the term inverse current time characteristic?

2. State the application of the synchronous motors. Discuss how a synchronous motor can function as a synchronous capacitor. Compare synchronous motors with induction motors drives?



3. What is Zener diode and how does it regulate the voltage? What happens to the series current, load current, and Zener current, when the d.c. the input voltage of a Zener regulator increase? Draw a neat diagram of the Zener regulator and explain it? 


4. With Reference to 3-phase transformers

a. Discuss the essential and desirable conditions to be fulfilling for operating two three-phase transformers in parallel.

b. What are the advantages of transformers bank of three 1-phase transformers over a unit three-phase transformers of the same KVA rating?

5. Sketch and describe the main engine shaft driven generator arrangement with an electronic system for frequency correction.

6. With respect to alternator onboard:

a. Briefly explain true power, Apparent power, and power factor?

b. The alternator is rated for 750 KVA at 0.85 PF, what is the maximum load (KW) that can be put on it? Would you be overloading the alternator if the KW reading were now 620 KW and the PF 0.80?

7. Write a short note on “electric shock”?

8. How will you fight a fire in a purifier room? How will you at least restrict the fire if you are the first person to sight the fire in the purifier room?

#etoquestions #etococ #imaginationhunt #electrical @etoquestions #etommdquestions

Read More »

Wednesday, 16 October 2019

Tips to reduce Plastic use - You must try


As we already know we are on the mission of reducing plastic waste. so, here are the different ways to live with less waste.

First, it’s important to know the four R’s
R = refuse what you don’t need
R= reduce what you do need
R= reuse by using what you have
R= recycle what you can


Today, we’ll start with refuse. Refusing is the first rule of living a zero-waste lifestyle. Think before accepting anything into your home. Turn down flyers and junk mail, freebies, party favors any other junk that will most likely go into the trash.
Each year people throw away 100 millions plastic grocery bags which take about 1000 years to breakdown.

1. Instead of taking plastic bags and creating more demand for them, use reusable cloth bags or even no bag, when possible. I used to think it was mandatory to use these plastic bags for your fruits and vegetables, but I recently discovered you can just use your own bag or even no bag, which is even better because why bring home extra plastic? You could also bring own jars to grocery stores to avoid bringing home any unnecessary plastic containers. I love when grocery stores sell the thing in bulk so that it’s really easy to do some zero waste shopping. You can either weigh your jars at the front beforehand or bring an extra of the same jar so you can weight it at checkout.

2. Instead of using a one-time disposable plastic straw, you can either refuse the straw completely or use an acrylic or steel straw instead. I personally like to drink my smoothies with a straw, so I have this acrylic straw for that specific purpose.

3. Instead of using this plastic cling wrap in your kitchen to preserve your food and leftovers, switch to using this sustainable and reusable food wrap. These are all-natural, organic and compostable. I believe they're made out of beeswax and they actually do a really good job at keeping your food fresh, even better than plastic in my opinion.

4. Instead of buying disposable plastic water bottles, opt for a reusable water bottle that you can fill up again and again. Glass and steel are probably best for your water bottle.

5. Instead of using disposable utensils. Do your best to avoid using disposable utensils. Instead you can bring silverware from the use or use portable made out of stainless steel or bamboo or leaf cutlery.



6. Over 4.7 billion plastic toothbrushes that will never biodegrade dumped in landfills and ocean each year. So you can make a huge impact just by switching out your plastic toothbrush for a sustainable bamboo toothbrush. Think of all plastic toothbrush that you use in one lifetime and imagine avoiding that waste completely, just by switching to something that’s biodegradable and compostable.

7. Lastly, reduce the amount of paper you bring into your home by switching to paperless whenever possible. Do this with your mail, your bills, your notes, and your books. U personally love reading ebooks, but I know some people love traditional books, so just do whatever works for you.

8. Instead of using a plastic straw use paper made straw.

I hope you liked tips on how to balanced life with less waste. I just want to remind you though: just take it one step at a time.. don’t be so hard on yourself. It’s a journey. All that matters is that you're becoming aware, more conscious of the environment and you’re doing your best, okay?

Everyone is at a different point in their journey and  No one is perfect. I am not totally zero waste yet. But I think the first step is awareness. And then after that, you will start to reduce your waste little by little. So let’s create a non-judgemental, welcoming space where we can just open up the discussion around reducing uor waste. And lets not judge others who aren’t aware of this lifestyle.

The best thing you can do is just be a living example of what you want to see in the world. And let your action speak louder than your words.

#enviroment #reduceplastic #saveearth #savetheplanet #zerowaste #pollution #imaginationhunt





Read More »

Saturday, 5 October 2019

NEVER EVER LOOSE HOPE


If you want to achieve success in your life, you need to work hard. You need to live with determination. You need to have patience and even after following all of these things, we will still have to face challenges in our life.

We Fail,
We Fall,
And become hopeless.

And everyone knows, Hopelessness is the biggest enemy of success. If you become hopeless, you will loose everything very easily.

Whenever you feel hopeless, just remember one thing ‘when you tried, again and again, you will definitely achieve the success.’



For example- When a giraffe mother gives birth to a baby, the giraffe mother is very tall and the baby giraffe falls on the ground with a force.

And as it tries to understand where it has fallen. Mother giraffe stand over it and kicks it really very hard. So, the baby giraffe falls at a distance and tries to understand what was happened with him and gather all its senses. Again the mother comes and stands over it and again gives it another hard kick. After that the baby giraffe understands, if I didn’t act now, I will keep getting kicks.’ Than he starts trying to get up with on its wobbly legs. But her mother kicks again.

Finally, the baby giraffe understand, “If I don’t stand and run, I will be kicked again and again. So, the baby giraffe starts running and at that moment, the mother comes and starts kissing the baby because the baby giraffe is ready to take care of itself. Because mother can’t stay with the baby all the time.

So if it goes away, who will protect the baby?

That’s why mother giraffe kick to the baby so that it learns how to stand, she kick again so that the baby remember how to stand. And the last kick is just to remind that not to stand up but start running.
In life, challenges will come. Sometimes we will fall; we will fail, but don’t lose your hope.

Whenever challenges come your way, no matter how many of time you will fail or fall, learn to get up and start running.

If you learn to get up, stand up and start running. Then you will reach the highest peak of success.👍💗




Read More »

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...