블로그 이미지
Sunny's

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2010. 6. 16. 19:28 JQUERY
jQuery 를 이용해서 HTML 테이블을 엑셀로 저장하는 간단한 방법입니다.

다음은 HTML 코드입니다.

<form action="/SaveToExcel.php" method="post" target="_blank"
    onsubmit='$("#dataToDisplay").val( $("<div>").append( $("#ReportTable").eq(0).clone() ).html() )'
>
    <pre><input type="image" src="/images/icons/save_excel.png"></pre>
   <pre><input type="hidden" id="dataToDisplay" name="dataToDisplay" />
</form>

설명
reportTable - 저장하기 원하는 테이블 ID
dataToDisplay - 서버로 POST될 베이블을 위한 hidden변수


폼의 onSubmit시에 저장할 HTML 테이블을 jQuery 메서드로 쉽게 처리할수 있다.


<table>을 포함한 HTML코드를 가져오는 부분의 처리가 중요하다.

jQuery.html() 메서드는 innerHTML만 가져오므로  table id를 기준으로 실행하면 <table> 태그가 빠지게 된다.

그래서 <div> 안에  전체 <table> 을 append하면  <div> <table>...</table> </div>  가 되고

여기서  .html() 을 실행하면  <table>...</table> 을 리턴하므로 원하는 결과를 얻을 수 있다.


서버소스
<?php
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: filename=export.xls");
// Fix for crappy IE bug in download.
header("Pragma: ");
header("Cache-Control: ");
?>
<html>
<head></head>
<body><?=$_REQUEST['dataToDisplay']?>
</body>
</html>

posted by Sunny's
2010. 2. 22. 19:23 .NET Framework

Versions Supported:  2008,2010

Keyboard Shortcut:  N/A

Menu Command:  File -> Export Template.

 

Are you always adding the same extra files to project templates?  Ever just wish you could have it all just "be" there?  Well you can with the Export Template Wizard!  It slices, it dices, er.okay it just makes templates but it really rocks!  How do you use it?  Just set up an existing project template the way you want it.  In this example, I always want a larry, curly, and moe class files with my console apps:

 

image_thumb 

 

 

Now go to File -> Export Template.  (NOTE: it will prompt you to save changes if you haven't already)

image_thumb2

 

 

You get the Export Template Wizard.  The first screen is where you choose to make a Project or Item template:

image_thumb5

 

I selected "Project template" for this example then clicked on "Next >" to get this dialog:

image_thumb11

 

Pay particular attention to the two choices at the bottom:  "Automatically import the template into Visual Studio" and "Display an explorer window on the output files folder".

 

Clicking "Finish" opens up my Exported Templates (output) folder:

image_thumb14

 

And when I go to create a new application, I see this in the dialog:

image_thumb19

 

And there you go:  instant template! 

Obviously there is lot more you can do and I would suggest starting here for more information on how to leverage this feature:

http://msdn.microsoft.com/en-us/library/ms185318.aspx

posted by Sunny's
prev 1 next