W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 2010-01-23 (토) 20:44:45 · 6935

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,187건
+
제목 글쓴이 날짜 조회
10-09-17 조회 2,345
10-09-16 조회 3,430
10-09-16 조회 2,155
10-09-16 조회 3,289
10-09-16 조회 2,230
10-09-16 조회 3,916
10-09-16 조회 2,170
10-09-16 조회 2,659
10-09-16 조회 2,172
10-09-15 조회 4,502
10-09-15 조회 2,858
10-09-15 조회 2,849
10-09-15 조회 2,852
10-09-15 조회 2,885
10-09-15 조회 2,633
10-09-15 조회 3,345
10-09-15 조회 2,842
10-09-15 조회 2,419
10-09-15 조회 4,278
10-09-15 조회 2,694
10-09-15 조회 2,908
10-09-15 조회 2,607
10-09-15 조회 3,511
10-09-15 조회 3,525
10-09-15 조회 3,184
10-09-15 조회 2,538
10-09-15 조회 2,738
10-09-15 조회 2,399
10-09-15 조회 2,416
10-09-15 조회 2,606
10-09-14 조회 4,130
10-09-11 조회 4,068
10-09-11 조회 2,995
10-09-11 조회 2,512
10-09-11 조회 2,702
10-09-11 조회 2,685
10-09-11 조회 2,564
10-09-11 조회 2,481
10-09-11 조회 2,381
10-09-11 조회 2,731
10-09-11 조회 2,826
10-09-11 조회 2,457
10-09-11 조회 2,457
10-09-11 조회 2,636
10-09-11 조회 3,107
10-09-11 조회 2,617
10-09-08 조회 2,997
10-09-08 조회 2,731
10-09-07 조회 3,505
10-09-07 조회 4,570
10-09-07 조회 3,890
10-09-07 조회 2,444
10-09-07 조회 3,427
10-09-07 조회 3,718
10-09-04 조회 2,986
10-08-29 조회 2,872
10-08-27 조회 4,175
10-08-27 조회 4,180
10-08-20 조회 7,055
10-08-06 조회 2,971
10-07-30 조회 5,732
10-07-27 조회 2,836
10-07-15 조회 3,176
10-07-06 조회 3,245
10-07-01 조회 3,127
10-07-01 조회 2,651
10-07-01 조회 2,883
10-07-01 조회 3,138
10-06-30 조회 3,031
10-06-30 조회 3,902
10-06-30 조회 2,897
10-06-30 조회 3,001
10-06-30 조회 2,463
10-06-30 조회 2,591
10-06-30 조회 2,609
10-06-30 조회 2,534
10-06-30 조회 2,531
10-06-30 조회 2,559
10-06-30 조회 2,700
10-06-30 조회 2,720
10-06-30 조회 4,130
10-06-30 조회 2,474
10-06-30 조회 3,154
10-06-30 조회 3,060
10-06-17 조회 3,161
10-06-16 조회 2,857
10-06-14 조회 3,426
10-06-13 조회 2,118
10-06-11 조회 2,773
10-06-11 조회 2,674
10-06-11 조회 4,382
10-06-11 조회 4,761
10-06-11 조회 3,452
10-06-01 조회 2,951
10-05-31 조회 3,654
10-05-31 조회 3,074
10-05-31 조회 2,633
10-05-22 조회 5,308
10-05-18 조회 2,990
10-05-18 조회 3,022